changes, not yet ok

This commit is contained in:
Wolfgang Hottgenroth 2016-10-06 22:22:50 +02:00
parent 36ffda7e5d
commit 5843c32d4b
5 changed files with 124 additions and 2 deletions

View File

@ -27,7 +27,7 @@
<option id="dk.xpg.msp430eclipse.compiler.option.includes.paths.1323710866" name="Include paths (-I)" superClass="dk.xpg.msp430eclipse.compiler.option.includes.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/inverter0ctrl/hottislib}&quot;"/>
</option>
<option id="dk.xpg.msp430eclipse.compiler.option.language.standard.995213149" superClass="dk.xpg.msp430eclipse.compiler.option.language.standard" useByScannerDiscovery="false" value="dk.xpg.msp430eclipse.compiler.option.language.standard.gnu99" valueType="enumerated"/>
<option id="dk.xpg.msp430eclipse.compiler.option.language.standard.995213149" name="Standard" superClass="dk.xpg.msp430eclipse.compiler.option.language.standard" useByScannerDiscovery="false" value="dk.xpg.msp430eclipse.compiler.option.language.standard.gnu99" valueType="enumerated"/>
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.223570634" name="C Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input"/>
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc.1904155844" name="C++ Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc"/>
</tool>

View File

@ -1,2 +1,7 @@
eclipse.preferences.version=1
msp430/DeviceSerialNumber=
msp430/MSP430TARGETMCU=msp430g2553
msp430/MSPDebugConnection=USB
msp430/MSPDebugDriver=rf2500
msp430/MSPDebugProtocol=SBW
msp430/MSPDebugTTYDevice=

96
src/inverterCtrl.c Normal file
View 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
View 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_ */

View File

@ -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();
}