Hello everyone. I am currently trying to drive a stepper motor via generating a step signal (from P3.6 on the MSP430), which is working fine, the part I am having trouble with is illuminating a LED from that same step signal. The LED will illuminate when the step signal (movemotor subroutine) is being called, however the issue is that the LED will sometimes stay on when this signal is not being called. The movemotor subroutine is called when a button connected to P2.2 is high (1).
Using an oscilloscope, I checked the step signal after being called, and it is sometimes high and sometimes low; the signal isn't 'stepping or oscillating high -> low -> high -> low -> high -> low... etc,' however it is terminating on either a logic high or logic low and holding that value. So I believe my issue is being able to ensure this signal always ends with a logic value of 'low'. I greatly appreciate any suggestions or comments to aid me in hopefully figuring this out.
Below is part of my program which I am trying to figure out a way to always end the signal with a logic level low:
#include "msp430xG46x.h" #include <intrinsics.h> // Intrinsic functions #include <stdio.h> #include <string.h> int ib1=0; unsigned int x; volatile unsigned int i; void delay(int x){ for(int i=0;i<1000;i++) for(int j=0; j<x; j++) i++; } void movemotor(int x){ P3DIR |= BIT6; if(ib1%2==0){ P3OUT |= BIT6; delay(10); } if(ib1%2==1){ P3OUT &= ~BIT6; delay(10); } ib1++; if(ib1==10000) ib1=0; } void button(){ volatile int btn=0; btn=P2IN&BIT2; if(btn==BIT2){ movemotor(1); } }