works better now, timing needs to be adjusted
This commit is contained in:
parent
bde508d6c3
commit
8a3d721314
@ -52,9 +52,11 @@ ISR(TIMER1_A0, TA1_ISR_Ovrfl) {
|
||||
}
|
||||
|
||||
ISR(TIMER1_A1, TA1_ISR_Comp) {
|
||||
__disable_interrupt();
|
||||
if (TA1IV & TA1IV_TACCR1) {
|
||||
P2OUT &= ~BIT1;
|
||||
}
|
||||
__enable_interrupt();
|
||||
}
|
||||
|
||||
|
||||
@ -80,15 +82,17 @@ void inverterInit() {
|
||||
void inverterSetFrequency(uint16_t f) {
|
||||
float ff = (float)f;
|
||||
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;
|
||||
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();
|
||||
activeOffset = currentOffset;
|
||||
TA1CCR0 = (uint16_t)slotLength;
|
||||
TA1CCR0 = sl;
|
||||
pulseWidthIdx = 0;
|
||||
__enable_interrupt();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user