works better now, timing needs to be adjusted

This commit is contained in:
Wolfgang Hottgenroth 2016-09-22 11:51:09 +02:00
parent bde508d6c3
commit 8a3d721314

View File

@ -52,9 +52,11 @@ ISR(TIMER1_A0, TA1_ISR_Ovrfl) {
} }
ISR(TIMER1_A1, TA1_ISR_Comp) { ISR(TIMER1_A1, TA1_ISR_Comp) {
__disable_interrupt();
if (TA1IV & TA1IV_TACCR1) { if (TA1IV & TA1IV_TACCR1) {
P2OUT &= ~BIT1; P2OUT &= ~BIT1;
} }
__enable_interrupt();
} }
@ -80,15 +82,17 @@ void inverterInit() {
void inverterSetFrequency(uint16_t f) { void inverterSetFrequency(uint16_t f) {
float ff = (float)f; float ff = (float)f;
float slotLength = 100.0 / (ff * 9.8e-6 * 20); float slotLength = 100.0 / (ff * 9.8e-6 * 20);
uint16_t sl = (uint16_t)slotLength;
uint8_t currentOffset = (activeOffset == 0) ? NUM_OF_SINE_VALUES : 0; uint8_t currentOffset = (activeOffset == 0) ? NUM_OF_SINE_VALUES : 0;
for (uint8_t i = 0; i < NUM_OF_SINE_VALUES; i++) { for (uint8_t i = 0; i < NUM_OF_SINE_VALUES; i++) {
pulseWidths[i + currentOffset] = (uint16_t)(slotLength * sineValues[i]); uint16_t pw = (uint16_t)(slotLength * sineValues[i]);
pulseWidths[i + currentOffset] = (pw == sl) ? (pw - 5) : pw;
} }
__disable_interrupt(); __disable_interrupt();
activeOffset = currentOffset; activeOffset = currentOffset;
TA1CCR0 = (uint16_t)slotLength; TA1CCR0 = sl;
pulseWidthIdx = 0; pulseWidthIdx = 0;
__enable_interrupt(); __enable_interrupt();
} }