From 4dea7fe8951e7565ed3b9efe9f5532b55e8ea86b Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 21 Sep 2016 17:27:22 +0200 Subject: [PATCH] not yet working --- src/inverter.c | 80 +++++++++++++++++++++++++++++++++++++++++++------- src/inverter.h | 2 +- src/main.c | 2 ++ 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/inverter.c b/src/inverter.c index ee5074e..0b2ee24 100644 --- a/src/inverter.c +++ b/src/inverter.c @@ -13,9 +13,47 @@ #include "inverter.h" +#define NUM_OF_SINE_VALUES 10 + +float sineValues[NUM_OF_SINE_VALUES] = { + 0.3090, + 0.5878, + 0.8090, + 0.9511, + 1.0000, + 0.9511, + 0.8090, + 0.5878, + 0.3090, + 0.0000, +}; + +volatile uint16_t pulseWidths[NUM_OF_SINE_VALUES * 2] = { 0,50,0,50,0,50,0,50,0,50,0,0,0,0,0,0,0,0,0,0 }; +volatile uint8_t activeOffset = 0; + + +volatile uint16_t uiSlotLength = 2040; ISR(TIMER1_A0, TA1_ISR_Ovrfl) { + static uint16_t myUiSlotLength = 0; + if (myUiSlotLength != uiSlotLength) { + TA1CCR0 = uiSlotLength; + myUiSlotLength = uiSlotLength; + } + + static uint8_t idx = 0; + + if (idx == 0) { + P1OUT ^= BIT1; + } + + TA1CCR1 = pulseWidths[idx + activeOffset]; + + idx++; + if (idx >= NUM_OF_SINE_VALUES) { + idx = 0; + } } //ISR(TIMER1_A1, TA1_ISR_Comp) { @@ -25,18 +63,38 @@ ISR(TIMER1_A0, TA1_ISR_Ovrfl) { void inverterInit() { - P2OUT &= ~BIT1; - P2DIR |= BIT1; - P2SEL |= BIT1; + P1OUT &= ~BIT1; + P1DIR |= BIT1; - P2OUT &= ~BIT0; - P2DIR |= BIT0; - P2SEL |= BIT0; + P2OUT &= ~BIT1; + P2DIR |= BIT1; + P2SEL |= BIT1; + + P2OUT &= ~BIT0; + P2DIR |= BIT0; + P2SEL |= BIT0; - TA1CTL = MC_1 | ID_1 | TASSEL_2 | TACLR; - TA1CCTL0 = CCIE | OUTMOD_4; - // TA1CCTL1 = OUTMOD_7; - TA1CCR0 = 100; - // TA1CCR1 = 62; + + + TA1CTL = MC_1 | ID_1 | TASSEL_2 | TACLR; + TA1CCTL0 = CCIE | OUTMOD_4; + TA1CCTL1 = OUTMOD_7; + TA1CCR0 = 5000; + TA1CCR1 = 0; +} + +void inverterSetFrequency(uint16_t f) { + float ff = (float)f; + float slotLength = 100.0 / (ff * 9.8e-6 * 20); + + uint8_t currentOffset = (activeOffset == 0) ? NUM_OF_SINE_VALUES : 0; + for (uint8_t i = 0; i < NUM_OF_SINE_VALUES; i++) { + pulseWidths[i + currentOffset] = (uint16_t)(slotLength * sineValues[i]); + } + + __disable_interrupt(); + activeOffset = currentOffset; + uiSlotLength = (uint16_t)slotLength; + __enable_interrupt(); } diff --git a/src/inverter.h b/src/inverter.h index 88470fa..ac26522 100644 --- a/src/inverter.h +++ b/src/inverter.h @@ -11,6 +11,6 @@ #include void inverterInit(); -void inverterSetFrequency(uint8_t f); +void inverterSetFrequency(uint16_t f); #endif /* INVERTER_H_ */ diff --git a/src/main.c b/src/main.c index 5f1bd95..00a4b83 100644 --- a/src/main.c +++ b/src/main.c @@ -30,6 +30,8 @@ int main() { __enable_interrupt(); + //inverterSetFrequency(100); + while (1) { } }