DC motor control (with L293D IC) gets skipped when controlling LEDs (via 74HC595
hi there,
i trying build object shows heatmap lights , moves @ same time. getting both parts work quite easy, have put them it's whole different story.
the movement of object done using dc motor, controlled l293d motor control chip. motor has move in 1 direction time , go in other direction, , cycle continues. used adafruits arduino lesson 15 (dc mototr reversing, http://goo.gl/ma9lq) , works brilliantly me.
i using motor: (http://goo.gl/wjywu), have tested others (servo , other dc) either fast, not strong enough or not working reason, changing motor not possible solution really.
for heatmap using 16 smd rgb leds (datasheet: http://goo.gl/0kncu), attached 6 74hc595 shift registers. control color , brightness of leds shiftpwm library (http://goo.gl/ixsja).
seperately of works perfectly, when put them problem appears:
the dc motor changes direction every 500 milliseconds now, when tell few leds change color, takes time/interrupts program long 1 movement command of motor gets skipped. let me illustrate:
how should go: how goes when leds instructed:
motor down motor down
motor down motor down
motor down motor down
motor up -*
motor up -*
motor up -*
motor down -*
motor down motor down
motor down motor down
*leds instructed here, , motor doesn't commands during time
this way, motor not command go before second command go down. because of motor goes down way long , (literally) crushes object.
i don't know how circumvent interruption of motor. 1 think thought using 2 timers, don't know how , don't know if work. if more information needed, please ask me , i'll try provide it. i'm beginner when comes arduino , electronics, pick things relatively fast.
i using arduino uno v3 , arduino software 1.0.5. fritzing file , image file of hardware setup attached arduino file.
this code:
i trying build object shows heatmap lights , moves @ same time. getting both parts work quite easy, have put them it's whole different story.
the movement of object done using dc motor, controlled l293d motor control chip. motor has move in 1 direction time , go in other direction, , cycle continues. used adafruits arduino lesson 15 (dc mototr reversing, http://goo.gl/ma9lq) , works brilliantly me.
i using motor: (http://goo.gl/wjywu), have tested others (servo , other dc) either fast, not strong enough or not working reason, changing motor not possible solution really.
for heatmap using 16 smd rgb leds (datasheet: http://goo.gl/0kncu), attached 6 74hc595 shift registers. control color , brightness of leds shiftpwm library (http://goo.gl/ixsja).
seperately of works perfectly, when put them problem appears:
the dc motor changes direction every 500 milliseconds now, when tell few leds change color, takes time/interrupts program long 1 movement command of motor gets skipped. let me illustrate:
how should go: how goes when leds instructed:
motor down motor down
motor down motor down
motor down motor down
motor up -*
motor up -*
motor up -*
motor down -*
motor down motor down
motor down motor down
*leds instructed here, , motor doesn't commands during time
this way, motor not command go before second command go down. because of motor goes down way long , (literally) crushes object.
i don't know how circumvent interruption of motor. 1 think thought using 2 timers, don't know how , don't know if work. if more information needed, please ask me , i'll try provide it. i'm beginner when comes arduino , electronics, pick things relatively fast.
i using arduino uno v3 , arduino software 1.0.5. fritzing file , image file of hardware setup attached arduino file.
this code:
code: [select]
const int shiftpwm_latchpin=8;
const bool shiftpwm_invertoutputs = false;
const bool shiftpwm_balanceload = false;
#include <shiftpwm.h>
unsigned char maxbrightness = 255;
unsigned char pwmfrequency = 60;
int numregisters = 7;
int numrgbleds = numregisters*8/3;
int enablepin = 6;
int in1pin = 10;
int in2pin = 9;
int speed = 150;
boolean motoron = false;
boolean motoroff = false;
unsigned long time;
void setup(){
serial.begin(57600);
shiftpwm.setamountofregisters(numregisters);
shiftpwm.start(pwmfrequency,maxbrightness);
pinmode(in1pin, output);
pinmode(in2pin, output);
pinmode(enablepin, output);
shiftpwm.setall(0);
for(int i=1; i<17; i++){
setled(i, 4, 176);
}
}
void loop(){
time = (round(millis()/5)*5);
leds();
if(motoroff == false){
if((time % 1000) < 500) {
motoron = true;
if((time % 1000) == 0) {
serial.print(time);
serial.println(" : motor up");
}
}
if((time % 1000) > 500) {
motoron = false;
if((time % 1000) == 510) {
serial.print(time);
serial.println(" : motor down");
}
}
}
if(time >= 10000){
motoroff = true;
setmotor(0, motoron);
serial.println("- - - end of story - - -");
}
}
void setmotor(int speed, boolean reverse){
analogwrite(enablepin, speed);
digitalwrite(in1pin, ! reverse);
digitalwrite(in2pin, reverse);
}
void setled(int ledid, int h_v, int s_v) {
string ledcolorstring1 = string("led set: ");
string ledcolorstring2 = string(" hsv: ");
serial.print(time);
serial.print(" : ");
serial.println(ledcolorstring1 + (ledid-1) + ledcolorstring2 +h_v+" "+s_v);
shiftpwm.sethsv(ledid-1, h_v, s_v, 255);
}
void setledoff(int ledid) {
string ledsetoffstring1 = string("led set: ");
string ledsetoffstring2 = string(" off");
serial.print(time);
serial.print(" : ");
serial.println(ledsetoffstring1 + (ledid-1) + ledsetoffstring2);
shiftpwm.setone(ledid-1, 0);
}
void leds() {
switch (time) {
case 3540:
serial.println("case 3540");
setled(12, 347, 222);
setled(13, 359, 255);
break;
case 5000:
serial.println("case 5000");
setled(2, 347, 222);
setled(3, 347, 222);
setled(4, 347, 222);
setled(5, 347, 222);
setled(6, 347, 222);
setled(7, 347, 222);
setled(11, 347, 222);
break;
case 5510:
serial.println("case 5510");
setled(4, 359, 255);
setled(6, 359, 255);
setled(11, 359, 255);
break;
case 7490:
serial.println("case 7490");
setled(4, 347, 222);
setled(2, 359, 255);
break;
}
}
does nobody have clue? or have posted in wrong area?
Arduino Forum > Using Arduino > Programming Questions > DC motor control (with L293D IC) gets skipped when controlling LEDs (via 74HC595
arduino
Comments
Post a Comment