diff --git a/src/inverterCtrl.c b/src/inverterCtrl.c index 3b1f18c..0400aec 100644 --- a/src/inverterCtrl.c +++ b/src/inverterCtrl.c @@ -19,10 +19,14 @@ volatile uint8_t pulseWidthIdx = 0; -volatile bool direction = false; +volatile bool direction = true; + +volatile uint32_t tick; ISR(TIMER1_A0, TA1_ISR_Ovrfl) { + tick++; + if (direction) { if (pulseWidthIdx == 0) { P2OUT |= BIT3; @@ -55,10 +59,10 @@ ISR(TIMER1_A0, TA1_ISR_Ovrfl) { void inverterCtrlInit() { - // start, stop - P2SEL &= ~(BIT3 | BIT4 | BIT5); - P2OUT &= ~(BIT3 | BIT4 | BIT5); - P2DIR |= BIT3 | BIT4 | BIT5; + // reset, start, stop + P2SEL &= ~(BIT2 | BIT3 | BIT4 | BIT5); + P2OUT &= ~(BIT2 | BIT3 | BIT4 | BIT5); + P2DIR |= BIT2 | BIT3 | BIT4 | BIT5; // start mark P2OUT &= ~BIT0; @@ -70,13 +74,29 @@ void inverterCtrlInit() { P1SEL |= BIT4; - TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR; + tick = 0; + TA1CTL = MC_0; TA1CCTL0 = CCIE | OUTMOD_4; TA1CCR0 = 0; + + P2OUT &= ~BIT2; + + volatile uint32_t w; + for (w = 0; w < 100000; w++); + + // remove reset from PWNs + P2OUT |= BIT2; + + for (w = 0; w < 100000; w++); + + TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR; + + } + void inverterCtrlSetFrequency(uint16_t f) { float ff = (float)f; float slotLength = 4 / (ff * 400e-9 * NUM_OF_SINE_VALUES);