three phases working, frequency switch also, polarity not yet clear
This commit is contained in:
@ -15,28 +15,31 @@
|
||||
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
extern TIM_HandleTypeDef htim5;
|
||||
|
||||
|
||||
#define NUM_OF_SINE_SLOT 30
|
||||
uint16_t freqOut = 100;
|
||||
const uint32_t FREQ_IN = 72E6;
|
||||
const uint32_t FREQ_IN = 1E6;
|
||||
const float PI = 3.14159;
|
||||
float slotAngle = 180.0 / NUM_OF_SINE_SLOT;
|
||||
float sineValues[NUM_OF_SINE_SLOT];
|
||||
uint16_t IV[NUM_OF_SINE_SLOT];
|
||||
volatile uint32_t timer1Cnt;
|
||||
|
||||
typedef struct {
|
||||
uint8_t slotCnt;
|
||||
bool running;
|
||||
GPIO_TypeDef *bridgePolarityPort;
|
||||
uint16_t bridgePolarityPin;
|
||||
IRQn_Type irqType;
|
||||
TIM_HandleTypeDef *handle;
|
||||
uint32_t channel;
|
||||
} timerSupport_t;
|
||||
|
||||
#define NUM_OF_TIMER 3
|
||||
timerSupport_t timerSupport[NUM_OF_TIMER];
|
||||
volatile timerSupport_t timerSupport[NUM_OF_TIMER];
|
||||
|
||||
|
||||
|
||||
@ -46,29 +49,27 @@ void inverterBegin() {
|
||||
sineValues[i] = sinf(angle / 180 * PI);
|
||||
}
|
||||
|
||||
// TODO Configure pins for all three bridges
|
||||
timerSupport[0].handle = &htim2;
|
||||
timerSupport[0].running = false;
|
||||
timerSupport[0].slotCnt = 0;
|
||||
timerSupport[1].handle = &htim3;
|
||||
timerSupport[0].bridgePolarityPort = BridgePolarity0_GPIO_Port;
|
||||
timerSupport[0].bridgePolarityPin = BridgePolarity0_Pin;
|
||||
timerSupport[0].irqType = TIM2_IRQn;
|
||||
timerSupport[0].channel = TIM_CHANNEL_1;
|
||||
timerSupport[1].handle = &htim5;
|
||||
timerSupport[1].running = false;
|
||||
timerSupport[1].slotCnt = 0;
|
||||
timerSupport[1].bridgePolarityPort = BridgePolarity1_GPIO_Port;
|
||||
timerSupport[1].bridgePolarityPin = BridgePolarity1_Pin;
|
||||
timerSupport[1].irqType = TIM5_IRQn;
|
||||
timerSupport[1].channel = TIM_CHANNEL_2;
|
||||
timerSupport[2].handle = &htim4;
|
||||
timerSupport[2].running = false;
|
||||
timerSupport[2].slotCnt = 0;
|
||||
|
||||
__HAL_TIM_ENABLE_IT(&htim2, TIM_IT_UPDATE);
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
__HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);
|
||||
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||
__HAL_TIM_ENABLE_IT(&htim4, TIM_IT_UPDATE);
|
||||
HAL_NVIC_SetPriority(TIM4_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM4_IRQn);
|
||||
|
||||
HAL_NVIC_SetPriority(TIM1_CC_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
|
||||
timerSupport[2].bridgePolarityPort = BridgePolarity2_GPIO_Port;
|
||||
timerSupport[2].bridgePolarityPin = BridgePolarity2_Pin;
|
||||
timerSupport[2].irqType = TIM4_IRQn;
|
||||
timerSupport[2].channel = TIM_CHANNEL_1;
|
||||
}
|
||||
|
||||
void inverterSetFrequency(uint8_t freqOut) {
|
||||
@ -77,12 +78,13 @@ void inverterSetFrequency(uint8_t freqOut) {
|
||||
IV[i] = (uint16_t)(sineValues[i] * 0.9 * slotWidth);
|
||||
}
|
||||
|
||||
HAL_TIM_OC_Stop_IT(&htim1, TIM_CHANNEL_1);
|
||||
HAL_TIM_OC_Stop_IT(&htim1, TIM_CHANNEL_2);
|
||||
HAL_TIM_OC_Stop_IT(&htim1, TIM_CHANNEL_3);
|
||||
HAL_TIM_Base_Stop(&htim1);
|
||||
__HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE);
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
||||
HAL_TIM_PWM_Stop_DMA(timerSupport[i].handle, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Stop_DMA(timerSupport[i].handle, timerSupport[i].channel);
|
||||
__HAL_TIM_DISABLE_IT(timerSupport[i].handle, TIM_IT_UPDATE);
|
||||
|
||||
timerSupport[i].slotCnt = 0;
|
||||
timerSupport[i].running = false;
|
||||
@ -90,10 +92,14 @@ void inverterSetFrequency(uint8_t freqOut) {
|
||||
__HAL_TIM_SET_AUTORELOAD(timerSupport[i].handle, slotWidth);
|
||||
}
|
||||
|
||||
// TODO Set the 120<32> values for the channels
|
||||
HAL_TIM_OC_Start_IT(&htim1, TIM_CHANNEL_1);
|
||||
HAL_TIM_OC_Start_IT(&htim1, TIM_CHANNEL_2);
|
||||
HAL_TIM_OC_Start_IT(&htim1, TIM_CHANNEL_3);
|
||||
HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
|
||||
|
||||
timer1Cnt = 0;
|
||||
__HAL_TIM_SET_AUTORELOAD(&htim1, slotWidth);
|
||||
HAL_TIM_Base_Start_IT(&htim1);
|
||||
__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
@ -106,28 +112,32 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef * htim) {
|
||||
if (htim->Instance == TIM1) {
|
||||
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
|
||||
HAL_GPIO_TogglePin(LED2_PIN_GPIO_Port, LED2_PIN_Pin);
|
||||
if (htim == &htim1) {
|
||||
HAL_GPIO_TogglePin(Sync_GPIO_Port, Sync_Pin);
|
||||
if (timer1Cnt == 0) {
|
||||
if (! timerSupport[0].running) {
|
||||
HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_SET);
|
||||
timerSupport[0].running = true;
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[0].handle, TIM_CHANNEL_1, (uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
__HAL_TIM_ENABLE_IT(timerSupport[0].handle, TIM_IT_UPDATE);
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[0].handle, timerSupport[0].channel, (uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
}
|
||||
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {
|
||||
HAL_GPIO_TogglePin(LED3_PIN_GPIO_Port, LED3_PIN_Pin);
|
||||
} else if (timer1Cnt == ((NUM_OF_SINE_SLOT * 2) / 3)) {
|
||||
if (! timerSupport[1].running) {
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
|
||||
timerSupport[1].running = true;
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[1].handle, TIM_CHANNEL_1, (uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[1].handle, timerSupport[1].channel, (uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
__HAL_TIM_ENABLE_IT(timerSupport[1].handle, TIM_IT_UPDATE);
|
||||
}
|
||||
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
|
||||
HAL_GPIO_TogglePin(LED4_PIN_GPIO_Port, LED4_PIN_Pin);
|
||||
} else if (timer1Cnt == ((NUM_OF_SINE_SLOT * 2) * 2 / 3)) {
|
||||
if (! timerSupport[2].running) {
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
|
||||
timerSupport[2].running = true;
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[2].handle, TIM_CHANNEL_1, (uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[2].handle, timerSupport[2].channel, (uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
__HAL_TIM_ENABLE_IT(timerSupport[2].handle, TIM_IT_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
timer1Cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define INVERTER_H_
|
||||
|
||||
|
||||
void inverterInit();
|
||||
void inverterBegin();
|
||||
void inverterSetFrequency(uint8_t freqOut);
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
void blink(void *handle) {
|
||||
HAL_GPIO_TogglePin(LED_PIN_GPIO_Port, LED_PIN_Pin);
|
||||
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
||||
}
|
||||
|
||||
void my_setup_1() {
|
||||
@ -44,8 +44,20 @@ void my_errorHandler() {
|
||||
HAL_GPIO_WritePin(ERROR_PIN_GPIO_Port, ERROR_PIN_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void testSwitchFrequency1(void *handle) {
|
||||
inverterSetFrequency(100);
|
||||
}
|
||||
void testSwitchFrequency2(void *handle) {
|
||||
inverterSetFrequency(50);
|
||||
}
|
||||
|
||||
void my_setup_2() {
|
||||
inverterBegin();
|
||||
|
||||
inverterSetFrequency(50);
|
||||
schAdd(testSwitchFrequency1, NULL, 5000, 0);
|
||||
schAdd(testSwitchFrequency2, NULL, 10000, 0);
|
||||
schAdd(testSwitchFrequency1, NULL, 15000, 0);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user