View previous topic :: View next topic |
Author |
Message |
erhane
Joined: 01 Jul 2014 Posts: 41
|
[SOLVED]Driving Multiple DC Motors Problem (RDA Interrupt) |
Posted: Wed Aug 20, 2014 7:58 am |
|
|
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: 19549
|
|
Posted: Wed Aug 20, 2014 8:08 am |
|
|
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
|
|
Posted: Wed Aug 20, 2014 1:20 pm |
|
|
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
|
|
Posted: Thu Aug 21, 2014 7:10 am |
|
|
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. |
|
|
|