CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Controlling two dc motors simultaneously in closed loop.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
corcobado
Guest







Controlling two dc motors simultaneously in closed loop.
PostPosted: Mon Nov 21, 2005 9:42 am     Reply with quote

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 Embarassed
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Controlling two dc motors simultaneously in closed loop.
PostPosted: Mon Nov 21, 2005 12:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 21, 2005 1:37 pm     Reply with quote

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







PostPosted: Tue Nov 22, 2005 3:42 am     Reply with quote

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 Razz
Guest








PostPosted: Thu Nov 24, 2005 4:20 am     Reply with quote

Any more suggestions please?

Thanx Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group