I'm trying to capture pulses like a logic analyzer.
I hope the change of state of the leg and I time in microsgundos until it changes state.
I've been reading you can do with the way TIMER_A 'CAP', but I do not understand how it works, and vector used.
I tried this, but not fast enough (it is a part of the code):
#######################################
#include <msp430g2553.h>
#define MAXPULSE 25000
#define BUTTON BIT3
uint16_t pulses[100][2];
uint8_t currentpulse = 0;
uint16_t highpulse, lowpulse;
DCOCTL = 0x00; // Set DCOCLK to 1MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
void capture(void) {
while(1){
highpulse = lowpulse = 0;
while ((BUTTON & P1IN)) { // pin is still HIGH
highpulse++;
__delay_cycles(1);
if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse=0;
return;
}
}
pulses[currentpulse][1] = highpulse;
while ((BUTTON & ~P1IN)) { // pin is still LOW
lowpulse++;
__delay_cycles(1);
if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse=0;
return;
}
}
pulses[currentpulse][0] = lowpulse;
currentpulse++;
}
}
#######################################
Regards