changes, not yet ok
This commit is contained in:
96
src/inverterCtrl.c
Normal file
96
src/inverterCtrl.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* inverter.c
|
||||
*
|
||||
* Created on: 19.09.2016
|
||||
* Author: dehottgw
|
||||
*/
|
||||
|
||||
|
||||
#include "inverterCtrl.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <msp430g2553.h>
|
||||
#include <isr_compat.h>
|
||||
|
||||
|
||||
#define NUM_OF_SINE_VALUES 20
|
||||
|
||||
|
||||
volatile uint8_t pulseWidthIdx = 0;
|
||||
|
||||
|
||||
ISR(TIMER1_A0, TA1_ISR_Ovrfl) {
|
||||
if (pulseWidthIdx == 0) {
|
||||
P2OUT |= BIT3;
|
||||
}
|
||||
|
||||
pulseWidthIdx++;
|
||||
if (pulseWidthIdx >= NUM_OF_SINE_VALUES) {
|
||||
pulseWidthIdx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ISR(TIMER1_A1, TA1_ISR_Comp) {
|
||||
__disable_interrupt();
|
||||
uint16_t taiv = TA1IV;
|
||||
if (P2OUT & BIT3) {
|
||||
if (taiv == TA1IV_TACCR1) {
|
||||
P2OUT |= BIT4;
|
||||
} else if (taiv == TA1IV_TACCR2) {
|
||||
P2OUT |= BIT5;
|
||||
}
|
||||
}
|
||||
__enable_interrupt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void inverterCtrlInit() {
|
||||
// start, stop
|
||||
P2SEL &= ~(BIT3 | BIT4 | BIT5);
|
||||
P2OUT &= ~(BIT3 | BIT4 | BIT5);
|
||||
P2DIR |= BIT3 | BIT4 | BIT5;
|
||||
|
||||
// start mark
|
||||
P2OUT &= ~BIT0;
|
||||
P2DIR |= BIT0;
|
||||
P2SEL |= BIT0;
|
||||
|
||||
// smclk out
|
||||
P1DIR |= BIT4;
|
||||
P1SEL |= BIT4;
|
||||
|
||||
|
||||
TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR;
|
||||
|
||||
TA1CCTL0 = CCIE | OUTMOD_4;
|
||||
TA1CCTL1 = CCIE;
|
||||
TA1CCTL2 = CCIE;
|
||||
TA1CCR0 = 0;
|
||||
TA1CCR1 = 0;
|
||||
TA1CCR2 = 0;
|
||||
}
|
||||
|
||||
|
||||
void inverterCtrlSetFrequency(uint16_t f) {
|
||||
float ff = (float)f;
|
||||
float slotLength = 2 / (ff * 400e-9 * NUM_OF_SINE_VALUES);
|
||||
uint16_t sl = (uint16_t)slotLength;
|
||||
float phase2start = slotLength / 3;
|
||||
uint16_t p2s = (uint16_t)phase2start;
|
||||
float phase3start = slotLength / 3 * 2;
|
||||
uint16_t p3s = (uint16_t)phase3start;
|
||||
|
||||
|
||||
__disable_interrupt();
|
||||
TA1CTL = MC_0;
|
||||
P2OUT &= ~(BIT3 | BIT4 | BIT5);
|
||||
TA1CCR0 = sl;
|
||||
TA1CCR1 = p2s;
|
||||
TA1CCR2 = p3s;
|
||||
pulseWidthIdx = 0;
|
||||
TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR;
|
||||
__enable_interrupt();
|
||||
}
|
16
src/inverterCtrl.h
Normal file
16
src/inverterCtrl.h
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* inverter.h
|
||||
*
|
||||
* Created on: 19.09.2016
|
||||
* Author: dehottgw
|
||||
*/
|
||||
|
||||
#ifndef INVERTERCTRL_H_
|
||||
#define INVERTERCTRL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void inverterCtrlInit();
|
||||
void inverterCtrlSetFrequency(uint16_t f);
|
||||
|
||||
#endif /* INVERTERCTRL_H_ */
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "time.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
#include "inverterCtrl.h"
|
||||
|
||||
|
||||
|
||||
@ -25,18 +26,22 @@ int main() {
|
||||
// highest possible system clock
|
||||
DCOCTL = DCO0 | DCO1 | DCO2;
|
||||
BCSCTL1 = XT2OFF | RSEL0 | RSEL1 | RSEL2 | RSEL3;
|
||||
BCSCTL2 = 0;
|
||||
BCSCTL2 = DIVS_1;
|
||||
BCSCTL3 = 0;
|
||||
|
||||
|
||||
timeInit();
|
||||
schInit();
|
||||
inverterCtrlInit();
|
||||
|
||||
// schAdd(displayExec, NULL, 0, DISPLAY_CYCLE);
|
||||
|
||||
|
||||
__enable_interrupt();
|
||||
|
||||
inverterCtrlSetFrequency(50);
|
||||
|
||||
|
||||
while (1) {
|
||||
schExec();
|
||||
}
|
||||
|
Reference in New Issue
Block a user