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

[SOLVED]Driving Multiple DC Motors Problem (RDA Interrupt)

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



Joined: 01 Jul 2014
Posts: 41

View user's profile Send private message Send e-mail

[SOLVED]Driving Multiple DC Motors Problem (RDA Interrupt)
PostPosted: Wed Aug 20, 2014 7:58 am     Reply with quote

Hello,

I designed a system which has 16 DC Motors and 1 MCU 16f1946.

MCU driving DC motors via I/Os. I tell MCU which DC motor to drive and which direction via eusart(RS485).

Problem is i only need to run DC motors for 20ms. After it should stop itself.

Thats why, for example, when i tell MCU to run Motor1:
//
Output_high(Motor1_Pin1);
Output_low(Motor1_Pin2);
delay_ms(20);
Output_low(Motor1_Pin1);//

Problem is while this motor is turning i need to start others "randomly".

While code in delay_ms() i can not send data via RDA interrupt.
Is there any other ways to run 16DC motors randomly?

NOTE=
removing delay_ms() and tell MCU every stop time is my last choice.

Thank you.


Last edited by erhane on Thu Aug 21, 2014 7:08 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Aug 20, 2014 8:08 am     Reply with quote

You need to use a tick interrupt (perhaps 100Hz), and have counters for each motor, that the external code loads, decremented in the tick.

If each counter is non zero, turn the corresponding motor on, otherwise off.

Then in the external code, load the counter for the first motor with 2000 (20 seconds), and at random times after this, load the counters for the other motors with the times you want for these.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Wed Aug 20, 2014 1:20 pm     Reply with quote

You want to run the motor for 20ms? Very few mechanical motors can do much of anything with a 20ms "pulse". If you mean 20 seconds, then Ttelmahs approach is correct with the counter for each motor that you load to start the motor and when the interrupt tic counter gets it down to zero, turns it off. That allows multiple motors to start at different times (and even have different run times depending on what you load the counter with).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
erhane



Joined: 01 Jul 2014
Posts: 41

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 21, 2014 7:10 am     Reply with quote

Thank you fellas, i solved my problem with your suggestions.

In addition, gpsmikey, you are right 20ms struggling my system. that is why i extended it to 200ms. now it is ok.
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