Hi,
I'm trying to figure out the debounce routine in this code and I'm also trying to modify it so the sensor will also immediately send a message when the button goes from 0->1. It only sends a message (immediately) when the button goes from 1->0.
The sensor sends messages at every 5 seconds
I'm pretty new to embedded system and I'm at a loss reagding this button routine.
I would appreciate any help.
Sincerely,
Larissa Eglem.
#include <intrinsics.h>
#include "io430.h"
#include "config.h"
void main(void)
{
//stop watchdog
WDTCTL = WDTPW + WDTHOLD;
//Initiates DCO
clockInit();
//Initiate peripherals
btInitIO();
serialInit();
//Initiates watchdog
WDT_FEED;
__enable_interrupt();
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
while(1)
{
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
if (tempReady)
{
tempReady = 0;
__no_operation(); // SET BREAKPOINT HERE
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
}
}
}
/*! \brief sentor tx pins configuration */
static void serialInitIO(void)
{
//IO
TX_PSEL &= ~TX_BIT;
TX_PSEL &= ~TX_PULL;
//hilgh level output
TX_PDIR |= TX_BIT;
TX_HIGH;
//low level output
TX_PDIR |= TX_PULL;
TX_POUT |= TX_PULL;
}
/*button pin configuration */
static void btInitIO(void)
{
// GPIO and input
BT_PSEL &= ~BT_BIT;
BT_PDIR &= ~BT_BIT;
}
Now, here is the interruption:
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
WDT_FEED;
switch(dbSt)
{
case 0:
if(BT_PIN & BT_BIT)
{
dbCount++;
if(dbCount >= DB_LIMIT)
{
dbTxOffPending = 1; //need to send message with zeros
sensorVal = 0; //value of sensor (0 - button disconnected)
dbSt = 1;
}
}
else
{
dbCount = 0;
sensorVal = 1;
}
break;
case 1:
if(!(BT_PIN & BT_BIT))
{
dbCount++;
if(dbCount >= DB_LIMIT)
{
dbSt = 0;
sensorVal = 1;
}
}
else
{
dbCount = 0;
sensorVal = 0;
}
break;
}