not yet working
This commit is contained in:
parent
b69ebbb5ba
commit
4dea7fe895
@ -13,9 +13,47 @@
|
|||||||
|
|
||||||
#include "inverter.h"
|
#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) {
|
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) {
|
//ISR(TIMER1_A1, TA1_ISR_Comp) {
|
||||||
@ -25,6 +63,9 @@ ISR(TIMER1_A0, TA1_ISR_Ovrfl) {
|
|||||||
|
|
||||||
|
|
||||||
void inverterInit() {
|
void inverterInit() {
|
||||||
|
P1OUT &= ~BIT1;
|
||||||
|
P1DIR |= BIT1;
|
||||||
|
|
||||||
P2OUT &= ~BIT1;
|
P2OUT &= ~BIT1;
|
||||||
P2DIR |= BIT1;
|
P2DIR |= BIT1;
|
||||||
P2SEL |= BIT1;
|
P2SEL |= BIT1;
|
||||||
@ -34,9 +75,26 @@ void inverterInit() {
|
|||||||
P2SEL |= BIT0;
|
P2SEL |= BIT0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TA1CTL = MC_1 | ID_1 | TASSEL_2 | TACLR;
|
TA1CTL = MC_1 | ID_1 | TASSEL_2 | TACLR;
|
||||||
TA1CCTL0 = CCIE | OUTMOD_4;
|
TA1CCTL0 = CCIE | OUTMOD_4;
|
||||||
// TA1CCTL1 = OUTMOD_7;
|
TA1CCTL1 = OUTMOD_7;
|
||||||
TA1CCR0 = 100;
|
TA1CCR0 = 5000;
|
||||||
// TA1CCR1 = 62;
|
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();
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void inverterInit();
|
void inverterInit();
|
||||||
void inverterSetFrequency(uint8_t f);
|
void inverterSetFrequency(uint16_t f);
|
||||||
|
|
||||||
#endif /* INVERTER_H_ */
|
#endif /* INVERTER_H_ */
|
||||||
|
@ -30,6 +30,8 @@ int main() {
|
|||||||
|
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
|
||||||
|
//inverterSetFrequency(100);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user