From 86f7ef98f388c7d418d7f2c3ce46086d3ba51eaa Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 25 Sep 2016 22:47:50 +0200 Subject: [PATCH] symmetric wave --- src/inverter.c | 12 ++++++++---- src/main.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/inverter.c b/src/inverter.c index 1a4a01c..a2f57ee 100644 --- a/src/inverter.c +++ b/src/inverter.c @@ -46,7 +46,6 @@ volatile uint8_t activeOffset = 0; ISR(TIMER1_A0, TA1_ISR_Ovrfl) { if (pulseWidthIdx == 0) { - P1OUT ^= (BIT1 | BIT0); } uint16_t pw = pulseWidths[pulseWidthIdx + activeOffset]; @@ -63,8 +62,11 @@ ISR(TIMER1_A0, TA1_ISR_Ovrfl) { ISR(TIMER1_A1, TA1_ISR_Comp) { __disable_interrupt(); - if (TA1IV & TA1IV_TACCR1) { + uint16_t taiv = TA1IV; + if (taiv & TA1IV_TACCR1) { P2OUT &= ~BIT1; + } else if ((taiv && TA1IV_TACCR2) && (pulseWidthIdx == 0)) { + P1OUT ^= (BIT1 | BIT0); } __enable_interrupt(); } @@ -86,8 +88,10 @@ void inverterInit() { TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR; TA1CCTL0 = CCIE | OUTMOD_4; TA1CCTL1 = CCIE; + TA1CCTL2 = CCIE; TA1CCR0 = 0; TA1CCR1 = 0; + TA1CCR2 = 1; } void inverterSetFrequency(uint16_t f) { @@ -97,8 +101,8 @@ void inverterSetFrequency(uint16_t f) { uint8_t currentOffset = (activeOffset == 0) ? NUM_OF_SINE_VALUES : 0; for (uint8_t i = 0; i < NUM_OF_SINE_VALUES; i++) { - uint16_t pw = (uint16_t)(slotLength * sineValues[i]); - pulseWidths[i + currentOffset] = (pw == sl) ? (pw - 25) : pw; + uint16_t pw = (uint16_t)(slotLength * 0.9 * sineValues[i]); + pulseWidths[i + currentOffset] = pw; } __disable_interrupt(); diff --git a/src/main.c b/src/main.c index 8409b01..0b1efe8 100644 --- a/src/main.c +++ b/src/main.c @@ -30,7 +30,7 @@ int main() { __enable_interrupt(); - inverterSetFrequency(75); + inverterSetFrequency(50); while (1) { }