View previous topic :: View next topic |
Author |
Message |
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
Bidirectional control of dc motor using different pwm |
Posted: Sat Oct 28, 2017 8:20 am |
|
|
Hello friends if i wanted to drive a motor in forward direction for some time (Let T1)using a pwm1 and then in reverse direction for another time (T2) using pwm2 . then how to do that in ccs c?? and how i determine T1 & T2.
If anyone has sample code then please share? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Oct 28, 2017 9:08 am |
|
|
The code ( software) is dependent upon the motor drive electronics.
We'd have to know make/model/specs of the 'motor interface' you have or plan to use.
The actual program concept is very simple
...
set direction of controller(CW)
set PWM
enable motor( on)
delay for T1 time
disable motor(off)
set direction controller(CCW)
set PWM
enable motor(on)
...
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Oct 28, 2017 10:55 am |
|
|
Also the 'motor' !!
it's all about the 'little' details....
I run 5HP DC motors for the CNC mill, some people like steppers (how many phases....) then there's the RC servo motors modded to run 360*...
'motor' is too vague.
details, more is better
Jay |
|
|
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
|
Posted: Sun Nov 12, 2017 11:14 am |
|
|
temtronic wrote: | Also the 'motor' !!
it's all about the 'little' details....
I run 5HP DC motors for the CNC mill, some people like steppers (how many phases....) then there's the RC servo motors modded to run 360*...
'motor' is too vague.
details, more is better
Jay |
I use normal 6v dc motor. But still can not configure how to use timer to determine the running time of a motor |
|
|
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
|
Posted: Sun Nov 12, 2017 11:20 am |
|
|
I uses the following code. But how do i use timer1 in this code to determine running time of motor
Code: | #include <18F2550.h>
#device ADC = 10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20M)
#define MOTOR_1A PIN_B0
#define MOTOR_1B PIN_B1
unsigned int16 i;
void main()
{
setup_adc(ADC_CLOCK_DIV_32);
setup_adc_ports(AN0);
set_adc_channel(0);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 250, 1);
delay_ms(100);
while(1)
{
i = read_adc();
output_high(MOTOR_1B);
output_low(MOTOR_1A);
set_pwm1_duty(i);
delay_ms(300);
output_low(MOTOR_1B);
output_high(MOTOR_1A);
delay_ms(300);// Wait
}} |
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Nov 12, 2017 11:31 am |
|
|
Use Timer1 interrupts to generate a tick (say 1 s).
Count the ticks for your forward and reverse times.
Mike |
|
|
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
|
Posted: Sun Nov 12, 2017 11:37 am |
|
|
Mike Walne wrote: | Use Timer1 interrupts to generate a tick (say 1 s).
Count the ticks for your forward and reverse times.
Mike |
I just started to learning pic Can u provide any code ?? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Nov 12, 2017 12:08 pm |
|
|
I don't want to sound cruel, but you're supposed to work it out for yourself.
That way you'll learn from your mistakes.
I was hoping I'd given you enough guidance to proceed.
So I'll go into more detail on one way to do it, but leave the coding to you.
(Bear in mind CCS provides many examples of how to do many tasks.)
Get Timer1 to generate an interrupt.
Either adjust the interrupt time to get a 1 second interrupt or count the interrupts until you have a 1 second tick.
Create a "run_time_counter".
Use the 1 second tick to decrement this counter until it reaches zero, then stop the counter from going negative.
So to go forward for 10 seconds :-
Set run_time_counter to 10.
Set up a while loop to run whilst run_time_counter is > zero.
Run motor going forwards in the while loop, and stop when it leaves.
Do something similar for reverse.
As I've presented it you will get rounding off errors etc.
You can sort it out, but you will have something to work on.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Mon Nov 13, 2017 7:49 am |
|
|
Additionally have a look at the software RTC in the code library. It might shed some light on your task. |
|
|
|