start/stop running
This commit is contained in:
parent
a50a5e2f00
commit
5e982f8926
@ -8,6 +8,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <msp430g2452.h>
|
||||
#include <isr_compat.h>
|
||||
|
||||
@ -71,25 +72,30 @@ ISR(TIMER0_A1, TA0_ISR_Comp) {
|
||||
__enable_interrupt();
|
||||
}
|
||||
|
||||
ISR(PORT1, PORT1_ISR) {
|
||||
uint16_t p1Ifg = P1IFG;
|
||||
if (p1Ifg & BIT3) {
|
||||
// start
|
||||
pulseWidthIdx = 0;
|
||||
TA0CTL = MC_1 | ID_0 | TASSEL_0 | TACLR;
|
||||
} else if (p1Ifg & BIT4) {
|
||||
// stop
|
||||
TA0CTL = MC_0;
|
||||
void inverterExec() {
|
||||
static bool running = false;
|
||||
|
||||
if (P1IN & BIT3) {
|
||||
if (! running) {
|
||||
// start
|
||||
pulseWidthIdx = 0;
|
||||
TA0CTL = MC_1 | ID_0 | TASSEL_0 | TACLR;
|
||||
running = true;
|
||||
}
|
||||
} else {
|
||||
if (running) {
|
||||
// stop
|
||||
TA0CTL = MC_0;
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void inverterInit() {
|
||||
// start, stop
|
||||
// BIT3: start, BIT4: stop
|
||||
// P1OUT &= (BIT3 | BIT4);
|
||||
// P1DIR &= (BIT3 | BIT4);
|
||||
// P1IES = BIT3;
|
||||
// P1IE |= BIT3 | BIT4;
|
||||
P1OUT &= (BIT3 | BIT4);
|
||||
P1DIR &= (BIT3 | BIT4);
|
||||
|
||||
// bridge direction
|
||||
P1OUT &= ~BIT2;
|
||||
@ -110,7 +116,8 @@ void inverterInit() {
|
||||
P1DIR &= ~BIT0;
|
||||
P1SEL |= BIT0;
|
||||
|
||||
TA0CTL = TA0CTL = MC_1 | ID_0 | TASSEL_0 | TACLR;
|
||||
//TA0CTL = MC_1 | ID_0 | TASSEL_0 | TACLR;
|
||||
TA0CTL = MC_0;
|
||||
|
||||
TA0CCTL0 = CCIE | OUTMOD_4;
|
||||
TA0CCTL1 = CCIE;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void inverterInit();
|
||||
void inverterExec();
|
||||
void inverterSetFrequency(uint16_t f);
|
||||
|
||||
#endif /* INVERTER_H_ */
|
||||
|
@ -31,6 +31,7 @@ int main() {
|
||||
inverterSetFrequency(50);
|
||||
|
||||
while (1) {
|
||||
inverterExec();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user