View previous topic :: View next topic |
Author |
Message |
corcobado Guest
|
Controlling two dc motors simultaneously in closed loop. |
Posted: Mon Nov 21, 2005 9:42 am |
|
|
Hi all,
I'm actually developing a project where I have to control simultaneously two brushed DC motors with single-phase optical encoders, using CAN bus comunication. I'm thinking in use a pic18f4480 device for cost-effective production.
My questions are the following:
Can I assign a single timer (timer 2 I think) for each PWM generating, with same frequency but independent duty cycle? I guess that RC2/CCP1 and RD4/ECCP1 outputs must be used for this purpose, is that correct?
On the other hand, I need an assynchronous counter for each encoder input. Can I use timer1 and timer3 to doing that, for example? In this case, which input pins could be assigned?
Timer0 should be used as an interrupt source for calculating PID routines for both servos, but I don't know if I need an additional timer for using CAN peripheral. Do you think that I can do everything with that micro or is better to choose a DSPic?
You help will be highly appreciated.
Best regards and sorry for my bad english |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: Controlling two dc motors simultaneously in closed loop. |
Posted: Mon Nov 21, 2005 12:41 pm |
|
|
corcobado wrote: | Can I assign a single timer (timer 2 I think) for each PWM generating, with same frequency but independent duty cycle |
Yes, you can do it with any CCP outputs. You can call set_pwm1_duty(iDuty1) then set_pwm2_duty(iDuty2). Just as you have described, both PWMs will be running off one timer with the dame frequency and different duty cycles. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Nov 21, 2005 1:37 pm |
|
|
I would suggest using interupts for the CAN module only. From main you can poll the timer 2 interupt flag to solve new values for the PWM dutys and then clear the flag. Its best to limit the number of interupts used and run more code in main. You don't need a DSPic.
So you need 2 timers with external inputs (timers 1 and 3), 2 PWM's (timer 2) and the CAN module. |
|
|
corcobado Guest
|
|
Posted: Tue Nov 22, 2005 3:42 am |
|
|
Thanks you Kender and Neutone for your replies.
Neutone, my idea is using a timer for generating an interruption, for example every 5 ms., where motor1 and 2 PID values will be calculated. That's the only way I know for speed calculating. I would rather to avoid polling methods because other threads must be executed, and I'm afraid that it could give me some troubles. Taking a look to datasheet I've observed that TMR1 and TMR3 are sharing their clock input pin. So I'm thinking in using timers like this:
TMR2 for PWM1 and PWM2 outputs.
TMR0 and TMR3 like 16-bit asynchronous counters.
TMR1 for servo interruption generating.
But I'm a little confused about if CAN peripheral needs for a timer to work. Do you think I'm in the right way?
Regards from Barcelona |
|
|
Guest
|
|
Posted: Thu Nov 24, 2005 4:20 am |
|
|
Any more suggestions please?
Thanx |
|
|
|