Hi,
I currently have a program which detects the level of one input pin, if this pin is high it activates an output pin, which in turn drives a relay.
The scenario I have is a pulse input whilst the input device into the 430 is active (i.e. every 2 seconds my device sends a pulse to the input pin on my 430).
At present my program detects the input and turns the output on for a specified count. The problem I am having is that when the count is over the output turns off, if this lands in between a pulse from my input device it periodically switches off when I don't want it to.
What I need to do is have a timer which resets every time the the input is detected, even if it is currently half way through counting from the last detection. I assume I need to use an interrupt but don't know how to do this.
Below is my code I have so far, any help would be appreciated. Thanks.
#include <msp430.h>
/*
* main.c
*/
volatile long int i;
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1SEL = 0x00; // setting all P1 pins to GPIO
P1DIR |= 0x01; // Set P1.0 to output direction
P1IN =0x00; // Set P1.0 to LOW
P1OUT =0x00; // Set P1.4 to LOW
while (1) // infinite loop
{
if ((0x10 & P1IN)) // check if P1.4 is high
{
P1OUT |= 0x01; // set P1.0 high
i=800000;
do(i--);
while (i !=0);
P1OUT &= ~0x01; // set P1.0 to low
}
}
}