Mateus 0 Posted June 25, 2014 Share Posted June 25, 2014 First of all a question, I just have to change the jumpers J3 connections if I use serial communication right? Hello, I've a project where the msp430g2553 makes an access control by password. The launch pad receives a password from a matrix keypad, and turns on a motor to lock the door, or to lock the door if a button is pressed from inside the "room" The project works fine, but sometimes the dc motor doesn't stop working, and it is happening randomly. can somebody help me? sorry for my terrible english the code and a circuit layout: /*lock door control*//* matrix keypad: S Quote Link to post Share on other sites
bluehash 1,581 Posted June 25, 2014 Share Posted June 25, 2014 I have not looked at your code. Can you control the motor without the keypad and all the extra peripherals. Try to unit test your motor. Are your keypad pins debounced? Quote Link to post Share on other sites
spirilis 1,265 Posted June 25, 2014 Share Posted June 25, 2014 I cleaned his code's formatting & spacing up in vim, reposting: /*lock door control*//* matrix keypad: S bluehash 1 Quote Link to post Share on other sites
abecedarian 330 Posted June 25, 2014 Share Posted June 25, 2014 I think one thing you're doing wrong is driving the lock and unlock functions wrong. You should be using the 1,2EN pin (pin 1) on the L293D to enable the motors, and pins 2, 7 to control motor direction. If 2 is high and 7 is low, motor goes one way; if 2 is low and 7 is high motor goes opposite. This does mean you'd have to take VCC off pin 1 and run that to another assigned pin on the MSP430. I don't have an L293D to test, but maybe something like below. Think of it like setting motor direction, then enabling the motors to spin. //if enable is low motor will not spin; lock and unlock signals do not matter const lockEnable = X; // X is launchpad pin to control drive enable // to unlock door: digitalWrite(lockEnable, LOW); // disable the drive circuit - guarantees motors won't run digitalWrite(unlock, LOW ); // set motor to unlock direction digitalWrite(lock, HIGH ); // lock must be opposite of unlock or motor won't spin digitalWrite(lockEnable, HIGH); // enable the drive circuit delay(500); // wait 1/2 second digitalWrite(lockEnable, LOW); // disable the drive circuit digitalWrite(open, HIGH); // turn on OPEN LED digitalWrite(close, LOW); // turn off CLOSE LED ... // to lock door: digitalWrite(lockEnable, LOW); // disable the drive circuit - guarantees motors won't run digitalWrite(unlock, HIGH ); // set motor to lock direction digitalWrite(lock, LOW ); // lock must be opposite of unlock or motor won't spin digitalWrite(lockEnable, HIGH); // enable the drive circuit delay(500); // wait 1/2 second digitalWrite(lockEnable, LOW); // disable the drive circuit digitalWrite(open, LOW); // turn off OPEN LED digitalWrite(close, HIGH); // turn on CLOSE LED Mateus 1 Quote Link to post Share on other sites
abecedarian 330 Posted June 25, 2014 Share Posted June 25, 2014 Another thing might be to put weak pull-down resistor from L293D pin 1 to ground to guarantee the motor is disabled when the unit powers up since the MSP pins' states are undefined on power up, usually. Mateus 1 Quote Link to post Share on other sites
Mateus 0 Posted June 25, 2014 Author Share Posted June 25, 2014 abecedarian I think I cant put a pull down resitor ai pin 1 of L293D, because its the enable pin. That is really what you ment? Quote Link to post Share on other sites
abecedarian 330 Posted June 25, 2014 Share Posted June 25, 2014 abecedarian I think I cant put a pull down resitor ai pin 1 of L293D, because its the enable pin. That is really what you ment? Yes, that's what I meant. A 4.7k resistor from pin 1 to ground, but only after moving pin 1 off of VCC and connecting it to a GPIO pin on the MSP430. msp pin ----+---- L293D pin 1 | > < - 4.7k > | gnd --------+ Mateus 1 Quote Link to post Share on other sites
Mateus 0 Posted June 25, 2014 Author Share Posted June 25, 2014 abecedarian I also didnt understand the pin lockEnable, I think its is not necessary because I can "tell" the motor to not spin through the pin lock and unlock. Quote Link to post Share on other sites
Mateus 0 Posted June 25, 2014 Author Share Posted June 25, 2014 Yes, that's what I meant. A 4.7k resistor from pin 1 to ground, but only after moving pin 1 off of VCC and connecting it to a GPIO pin on the MSP430. msp pin ----+---- L293D pin 1 | > < - 4.7k > | gnd --------+ now I understood totally makes sense Quote Link to post Share on other sites
Mateus 0 Posted June 25, 2014 Author Share Posted June 25, 2014 I think I fixed this (but I am still testing) I created an enable pin, that is the same wich enables the L293D const int enable = 19; pinMode(enable, OUTPUT); so, every time the motor works, I put (enable, HIGH) and after the work I put it LOW (enable, LOW) like that: digitalWrite(enable, HIGH); // enable the motor to work digitalWrite(Lock, LOW); // turn on the motor delay (500); digitalWrite(Lock, HIGH);// turn off the motor digitalWrite(enable, LOW); // disable the motor to work and I put a pull down resitor like this: msp pin 19 ----+---- L293D pin 1 | > < - 4.7k > | gnd --------+ Quote Link to post Share on other sites
abecedarian 330 Posted June 25, 2014 Share Posted June 25, 2014 If it were me, I'd use code like I posted earlier. Maybe put them into functions. Disable the motor driver, set the motor direction, enable the motor driver, pause then disable the motor driver. The resistor in the circuit will hold the 'enable' pin at ground until the MSP takes the pin high. Here's the basic circuit: Quote Link to post Share on other sites
Mateus 0 Posted June 25, 2014 Author Share Posted June 25, 2014 If it were me, I'd use code like I posted earlier. Maybe put them into functions. Disable the motor driver, set the motor direction, enable the motor driver, pause then disable the motor driver. The resistor in the circuit will hold the 'enable' pin at ground until the MSP takes the pin high. Here's the basic circuit: doorlock.png Thank for your answer man, you really helped me. Quote Link to post Share on other sites
Mateus 0 Posted June 25, 2014 Author Share Posted June 25, 2014 I am doing tests in my code, and now I have noticed a problem, when I turn on the launch pad, it recognizes the status (lock or unlock), but the motor doesn't work. Then if I change the status once, It start working ok. Quote Link to post Share on other sites
abecedarian 330 Posted June 25, 2014 Share Posted June 25, 2014 What does your code look like now? Mateus 1 Quote Link to post Share on other sites
Mateus 0 Posted June 25, 2014 Author Share Posted June 25, 2014 What does your code look like now? Im still working and I solved the problem of my last post, I think the only thing I need now is to be able to read the button '*' when the dor is unlocked, to lock it. The code I am using is commented in portuguese, you may not understand. /*Controle Porta do Quarto 3.0*/ /* teclado: S Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.