From 8bab83d75c3c1bd5fcf742b109d6ec004bf407a0 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sat, 15 Oct 2016 22:21:00 +0200 Subject: [PATCH] start hmi stuff, not yet working --- src/hmi.c | 39 +++++++++++++++++++++++++++++++++++++++ src/hmi.h | 19 +++++++++++++++++++ src/inverterCtrl.c | 33 +++++++++++++-------------------- src/inverterCtrl.h | 7 +++++++ src/main.c | 8 +++++--- 5 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/hmi.c create mode 100644 src/hmi.h diff --git a/src/hmi.c b/src/hmi.c new file mode 100644 index 0000000..d6aa56f --- /dev/null +++ b/src/hmi.c @@ -0,0 +1,39 @@ +/* + * hmi.c + * + * Created on: Oct 15, 2016 + * Author: wn + */ + +#include +#include "hmi.h" +#include "inverterCtrl.h" + + + +const uint32_t HMI_CYCLE = 50; +const uint32_t HMI_START_DELAY = 30; + + + +void hmiInit() { + +} + + +void hmiExec(void *handle) { + static uint8_t state = 0; + + switch (state) { + case 0: + inverterCtrlSetFrequency(50); + state = 1; + break; + case 1: + break; + default: + state = 0; + break; + } + +} diff --git a/src/hmi.h b/src/hmi.h new file mode 100644 index 0000000..1d4999c --- /dev/null +++ b/src/hmi.h @@ -0,0 +1,19 @@ +/* + * hmi.h + * + * Created on: Oct 15, 2016 + * Author: wn + */ + +#ifndef HMI_H_ +#define HMI_H_ + + +extern const uint32_t HMI_CYCLE; +extern const uint32_t HMI_START_DELAY; + + +void hmiInit(); +void hmiExec(void *handle); + +#endif /* HMI_H_ */ diff --git a/src/inverterCtrl.c b/src/inverterCtrl.c index 0400aec..33bb5c4 100644 --- a/src/inverterCtrl.c +++ b/src/inverterCtrl.c @@ -21,12 +21,11 @@ volatile uint8_t pulseWidthIdx = 0; volatile bool direction = true; -volatile uint32_t tick; +const uint32_t INVERTERCTRL_START_STEP1_DELAY = 1; +const uint32_t INVERTERCTRL_START_STEP2_DELAY = 10; ISR(TIMER1_A0, TA1_ISR_Ovrfl) { - tick++; - if (direction) { if (pulseWidthIdx == 0) { P2OUT |= BIT3; @@ -73,29 +72,23 @@ void inverterCtrlInit() { P1DIR |= BIT4; P1SEL |= BIT4; - - tick = 0; - - TA1CTL = MC_0; + TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR; TA1CCTL0 = CCIE | OUTMOD_4; TA1CCR0 = 0; - P2OUT &= ~BIT2; - - volatile uint32_t w; - for (w = 0; w < 100000; w++); - - // remove reset from PWNs - P2OUT |= BIT2; - - for (w = 0; w < 100000; w++); - - TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR; - - } +void inverterCtrlStartStep1(void *handle) { + P2OUT |= BIT2; +} + +void inverterCtrlStartStep2(void *handle) { + TA1CTL = MC_1 | ID_0 | TASSEL_2 | TACLR; + TA1CCTL0 = CCIE | OUTMOD_4; + TA1CCR0 = 0; +} + void inverterCtrlSetFrequency(uint16_t f) { float ff = (float)f; diff --git a/src/inverterCtrl.h b/src/inverterCtrl.h index ff895e7..c4e4886 100644 --- a/src/inverterCtrl.h +++ b/src/inverterCtrl.h @@ -10,7 +10,14 @@ #include +extern const uint32_t INVERTERCTRL_START_STEP1_DELAY; +extern const uint32_t INVERTERCTRL_START_STEP2_DELAY; + + void inverterCtrlInit(); void inverterCtrlSetFrequency(uint16_t f); +void inverterCtrlStartStep1(void *handle); +void inverterCtrlStartStep2(void *handle); + #endif /* INVERTERCTRL_H_ */ diff --git a/src/main.c b/src/main.c index 3fd3ace..a30c7b1 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ #include "time.h" #include "PontCoopScheduler.h" #include "inverterCtrl.h" - +#include "hmi.h" @@ -33,13 +33,15 @@ int main() { timeInit(); schInit(); inverterCtrlInit(); + hmiInit(); - // schAdd(displayExec, NULL, 0, DISPLAY_CYCLE); + schAdd(inverterCtrlStartStep1, NULL, INVERTERCTRL_START_STEP1_DELAY, 0); + schAdd(inverterCtrlStartStep2, NULL, INVERTERCTRL_START_STEP2_DELAY, 0); + schAdd(hmiExec, NULL, HMI_START_DELAY, HMI_CYCLE); __enable_interrupt(); - inverterCtrlSetFrequency(50); while (1) {