Compare commits
2 Commits
master
...
InFrequenc
Author | SHA1 | Date | |
---|---|---|---|
ef6c63b418 | |||
3b0e1cd72e |
@ -208,21 +208,21 @@ static void MX_RTC_Init(void)
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
sTime.Hours = 0x1;
|
||||
sTime.Minutes = 0x0;
|
||||
sTime.Seconds = 0x0;
|
||||
sTime.Hours = 1;
|
||||
sTime.Minutes = 0;
|
||||
sTime.Seconds = 0;
|
||||
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
DateToUpdate.Month = RTC_MONTH_JANUARY;
|
||||
DateToUpdate.Date = 0x1;
|
||||
DateToUpdate.Year = 0x0;
|
||||
DateToUpdate.Date = 1;
|
||||
DateToUpdate.Year = 0;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
@ -237,7 +237,7 @@ static void MX_TIM1_Init(void)
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 36;
|
||||
htim1.Init.Prescaler = 72;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 5000;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -271,7 +271,7 @@ static void MX_TIM2_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 36;
|
||||
htim2.Init.Prescaler = 72;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 5000;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -320,7 +320,7 @@ static void MX_TIM4_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim4.Instance = TIM4;
|
||||
htim4.Init.Prescaler = 36;
|
||||
htim4.Init.Prescaler = 72;
|
||||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim4.Init.Period = 5000;
|
||||
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -369,7 +369,7 @@ static void MX_TIM5_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim5.Instance = TIM5;
|
||||
htim5.Init.Prescaler = 36;
|
||||
htim5.Init.Prescaler = 72;
|
||||
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim5.Init.Period = 5000;
|
||||
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
|
@ -193,13 +193,12 @@ RCC.HCLKFreq_Value=72000000
|
||||
RCC.HSIState=RCC_HSI_ON
|
||||
RCC.I2S2Freq_Value=72000000
|
||||
RCC.I2S3Freq_Value=72000000
|
||||
RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FSMCFreq_Value,FamilyName,HCLKFreq_Value,HSIState,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,RCC_MCOSource,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value
|
||||
RCC.MCOFreq_Value=36000000
|
||||
RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FSMCFreq_Value,FamilyName,HCLKFreq_Value,HSIState,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value
|
||||
RCC.MCOFreq_Value=72000000
|
||||
RCC.PLLCLKFreq_Value=72000000
|
||||
RCC.PLLMCOFreq_Value=36000000
|
||||
RCC.PLLMUL=RCC_PLL_MUL9
|
||||
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||
RCC.RCC_MCOSource=RCC_MCO1SOURCE_PLLCLK
|
||||
RCC.SDIOFreq_Value=72000000
|
||||
RCC.SDIOHCLKDiv2FreqValue=36000000
|
||||
RCC.SYSCLKFreq_VALUE=72000000
|
||||
@ -207,6 +206,8 @@ RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
|
||||
RCC.TimSysFreq_Value=72000000
|
||||
RCC.USBFreq_Value=72000000
|
||||
RCC.VCOOutput2Freq_Value=8000000
|
||||
RTC.Format=RTC_FORMAT_BIN
|
||||
RTC.IPParameters=Format
|
||||
SH.S_TIM2_CH1_ETR.0=TIM2_CH1,PWM Generation1 CH1
|
||||
SH.S_TIM2_CH1_ETR.ConfNb=1
|
||||
SH.S_TIM4_CH1.0=TIM4_CH1,PWM Generation1 CH1
|
||||
@ -215,23 +216,23 @@ SH.S_TIM5_CH2.0=TIM5_CH2,PWM Generation2 CH2
|
||||
SH.S_TIM5_CH2.ConfNb=1
|
||||
TIM1.IPParameters=TIM_MasterOutputTrigger,TIM_MasterSlaveMode,Prescaler,Period
|
||||
TIM1.Period=5000
|
||||
TIM1.Prescaler=36
|
||||
TIM1.Prescaler=72
|
||||
TIM1.TIM_MasterOutputTrigger=TIM_TRGO_RESET
|
||||
TIM1.TIM_MasterSlaveMode=TIM_MASTERSLAVEMODE_DISABLE
|
||||
TIM2.IPParameters=Prescaler,Period,Pulse-PWM Generation1 CH1,OCPolarity_1
|
||||
TIM2.OCPolarity_1=TIM_OCPOLARITY_LOW
|
||||
TIM2.Period=5000
|
||||
TIM2.Prescaler=36
|
||||
TIM2.Prescaler=72
|
||||
TIM2.Pulse-PWM\ Generation1\ CH1=1000
|
||||
TIM4.IPParameters=Prescaler,Period,OCPolarity_1
|
||||
TIM4.OCPolarity_1=TIM_OCPOLARITY_LOW
|
||||
TIM4.Period=5000
|
||||
TIM4.Prescaler=36
|
||||
TIM4.Prescaler=72
|
||||
TIM5.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM5.IPParameters=Channel-PWM Generation2 CH2,Prescaler,Period,OCPolarity_2
|
||||
TIM5.OCPolarity_2=TIM_OCPOLARITY_LOW
|
||||
TIM5.Period=5000
|
||||
TIM5.Prescaler=36
|
||||
TIM5.Prescaler=72
|
||||
VP_RTC_No_RTC_Output.Mode=RTC_OUT_NO
|
||||
VP_RTC_No_RTC_Output.Signal=RTC_No_RTC_Output
|
||||
VP_SYS_VS_Systick.Mode=SysTick
|
||||
|
BIN
doc/InFrequencyShifting.xlsx
Normal file
BIN
doc/InFrequencyShifting.xlsx
Normal file
Binary file not shown.
Binary file not shown.
@ -6,10 +6,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifdef SEMIHOSTING_ENABLED
|
||||
#include <diag/Trace.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
@ -24,25 +20,24 @@ extern TIM_HandleTypeDef htim4;
|
||||
extern TIM_HandleTypeDef htim5;
|
||||
|
||||
|
||||
#define NUM_OF_SINE_SLOT 60
|
||||
const uint32_t FREQ_IN = 2E6;
|
||||
#define NUM_OF_SINE_SLOT 30
|
||||
const uint32_t SLOT_WIDTH = 1500;
|
||||
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;
|
||||
GPIO_TypeDef *startMarkPort;
|
||||
uint16_t startMarkPin;
|
||||
IRQn_Type irqType;
|
||||
TIM_HandleTypeDef *handle;
|
||||
uint32_t channel;
|
||||
uint8_t slotCnt;
|
||||
bool running;
|
||||
GPIO_TypeDef *bridgePolarityPort;
|
||||
uint16_t bridgePolarityPin;
|
||||
GPIO_TypeDef *startMarkPort;
|
||||
uint16_t startMarkPin;
|
||||
IRQn_Type irqType;
|
||||
TIM_HandleTypeDef *handle;
|
||||
uint32_t channel;
|
||||
} timerSupport_t;
|
||||
|
||||
#define NUM_OF_TIMER 3
|
||||
@ -52,132 +47,141 @@ volatile uint8_t phaseOrder[NUM_OF_TIMER];
|
||||
|
||||
|
||||
void inverterBegin() {
|
||||
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
|
||||
float angle = i * slotAngle;
|
||||
sineValues[i] = sinf(angle / 180 * PI);
|
||||
}
|
||||
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
|
||||
float slotAngle = 180.0 / NUM_OF_SINE_SLOT;
|
||||
float angle = i * slotAngle;
|
||||
float sineValues = sinf(angle / 180 * PI);
|
||||
IV[i] = (uint16_t)(sineValues[i] * 0.9 * SLOT_WIDTH);
|
||||
}
|
||||
|
||||
timerSupport[0].handle = &htim2;
|
||||
timerSupport[0].running = false;
|
||||
timerSupport[0].slotCnt = 0;
|
||||
timerSupport[0].bridgePolarityPort = BridgePolarity0_GPIO_Port;
|
||||
timerSupport[0].bridgePolarityPin = BridgePolarity0_Pin;
|
||||
timerSupport[0].irqType = TIM2_IRQn;
|
||||
timerSupport[0].channel = TIM_CHANNEL_1;
|
||||
timerSupport[0].startMarkPort = LED0_GPIO_Port;
|
||||
timerSupport[0].startMarkPin = LED0_Pin;
|
||||
timerSupport[0].handle = &htim2;
|
||||
timerSupport[0].running = false;
|
||||
timerSupport[0].slotCnt = 0;
|
||||
timerSupport[0].bridgePolarityPort = BridgePolarity0_GPIO_Port;
|
||||
timerSupport[0].bridgePolarityPin = BridgePolarity0_Pin;
|
||||
timerSupport[0].irqType = TIM2_IRQn;
|
||||
timerSupport[0].channel = TIM_CHANNEL_1;
|
||||
timerSupport[0].startMarkPort = LED0_GPIO_Port;
|
||||
timerSupport[0].startMarkPin = LED0_Pin;
|
||||
__HAL_TIM_SET_AUTORELOAD(timerSupport[0].handle, SLOT_WIDTH);
|
||||
|
||||
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[1].startMarkPort = LED1_GPIO_Port;
|
||||
timerSupport[1].startMarkPin = LED1_Pin;
|
||||
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[1].startMarkPort = LED1_GPIO_Port;
|
||||
timerSupport[1].startMarkPin = LED1_Pin;
|
||||
__HAL_TIM_SET_AUTORELOAD(timerSupport[1].handle, SLOT_WIDTH);
|
||||
|
||||
timerSupport[2].handle = &htim4;
|
||||
timerSupport[2].running = false;
|
||||
timerSupport[2].slotCnt = 0;
|
||||
timerSupport[2].bridgePolarityPort = BridgePolarity2_GPIO_Port;
|
||||
timerSupport[2].bridgePolarityPin = BridgePolarity2_Pin;
|
||||
timerSupport[2].irqType = TIM4_IRQn;
|
||||
timerSupport[2].channel = TIM_CHANNEL_1;
|
||||
timerSupport[2].startMarkPort = LED2_GPIO_Port;
|
||||
timerSupport[2].startMarkPin = LED2_Pin;
|
||||
timerSupport[2].handle = &htim4;
|
||||
timerSupport[2].running = false;
|
||||
timerSupport[2].slotCnt = 0;
|
||||
timerSupport[2].bridgePolarityPort = BridgePolarity2_GPIO_Port;
|
||||
timerSupport[2].bridgePolarityPin = BridgePolarity2_Pin;
|
||||
timerSupport[2].irqType = TIM4_IRQn;
|
||||
timerSupport[2].channel = TIM_CHANNEL_1;
|
||||
timerSupport[2].startMarkPort = LED2_GPIO_Port;
|
||||
timerSupport[2].startMarkPin = LED2_Pin;
|
||||
__HAL_TIM_SET_AUTORELOAD(timerSupport[2].handle, SLOT_WIDTH);
|
||||
|
||||
__HAL_TIM_SET_AUTORELOAD(&htim1, SLOT_WIDTH);
|
||||
}
|
||||
|
||||
void inverterStart(uint8_t freqOut, direction_t direction) {
|
||||
inverterStop();
|
||||
void inverterIncFrequency() {
|
||||
uint16_t currPsc = htim1->Instance->PSC;
|
||||
currPsc++;
|
||||
htim1->Instance->PSC = currPsc;
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++) {
|
||||
timerSupport[i].handle->Instance->PSC = currPsc;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t slotWidth = (FREQ_IN / (freqOut * NUM_OF_SINE_SLOT * 2));
|
||||
void inverterDecFrequency() {
|
||||
uint16_t currPsc = htim1->Instance->PSC;
|
||||
currPsc--;
|
||||
htim1->Instance->PSC = currPsc;
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++) {
|
||||
timerSupport[i].handle->Instance->PSC = currPsc;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SEMIHOSTING_ENABLE
|
||||
trace_printf("slotWidth: %d\n", slotWidth);
|
||||
#endif
|
||||
void inverterStart(direction_t direction) {
|
||||
inverterStop();
|
||||
|
||||
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
|
||||
IV[i] = (uint16_t)(sineValues[i] * 0.9 * slotWidth);
|
||||
}
|
||||
|
||||
if (direction == CLOCKWISE) {
|
||||
phaseOrder[0] = 0;
|
||||
phaseOrder[1] = 1;
|
||||
phaseOrder[2] = 2;
|
||||
} else {
|
||||
phaseOrder[0] = 0;
|
||||
phaseOrder[1] = 2;
|
||||
phaseOrder[2] = 1;
|
||||
}
|
||||
if (direction == CLOCKWISE) {
|
||||
phaseOrder[0] = 0;
|
||||
phaseOrder[1] = 1;
|
||||
phaseOrder[2] = 2;
|
||||
} else {
|
||||
phaseOrder[0] = 0;
|
||||
phaseOrder[1] = 2;
|
||||
phaseOrder[2] = 1;
|
||||
}
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
||||
timerSupport[i].slotCnt = 0;
|
||||
timerSupport[i].running = false;
|
||||
HAL_GPIO_WritePin(timerSupport[i].bridgePolarityPort,
|
||||
timerSupport[i].bridgePolarityPin, GPIO_PIN_RESET);
|
||||
__HAL_TIM_SET_AUTORELOAD(timerSupport[i].handle, slotWidth);
|
||||
__HAL_TIM_SET_COUNTER(timerSupport[i].handle, 0);
|
||||
}
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
||||
timerSupport[i].slotCnt = 0;
|
||||
timerSupport[i].running = false;
|
||||
HAL_GPIO_WritePin(timerSupport[i].bridgePolarityPort, timerSupport[i].bridgePolarityPin, GPIO_PIN_RESET);
|
||||
__HAL_TIM_SET_COUNTER(timerSupport[i].handle, 0);
|
||||
}
|
||||
|
||||
timer1Cnt = 0;
|
||||
__HAL_TIM_SET_AUTORELOAD(&htim1, slotWidth);
|
||||
__HAL_TIM_SET_COUNTER(&htim1, 0);
|
||||
HAL_TIM_Base_Start_IT(&htim1);
|
||||
__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE);
|
||||
timer1Cnt = 0;
|
||||
__HAL_TIM_SET_COUNTER(&htim1, 0);
|
||||
HAL_TIM_Base_Start_IT(&htim1);
|
||||
__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
void inverterStop() {
|
||||
HAL_TIM_Base_Stop(&htim1);
|
||||
__HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE);
|
||||
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, timerSupport[i].channel);
|
||||
__HAL_TIM_DISABLE_IT(timerSupport[i].handle, TIM_IT_UPDATE);
|
||||
HAL_GPIO_WritePin(timerSupport[i].startMarkPort,
|
||||
timerSupport[i].startMarkPin, GPIO_PIN_RESET);
|
||||
}
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
||||
HAL_TIM_PWM_Stop_DMA(timerSupport[i].handle, timerSupport[i].channel);
|
||||
__HAL_TIM_DISABLE_IT(timerSupport[i].handle, TIM_IT_UPDATE);
|
||||
HAL_GPIO_WritePin(timerSupport[i].startMarkPort, timerSupport[i].startMarkPin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void startPhase(uint8_t phaseIdx) {
|
||||
uint8_t timerIdx = phaseOrder[phaseIdx];
|
||||
if (! timerSupport[timerIdx].running) {
|
||||
HAL_GPIO_WritePin(timerSupport[timerIdx].startMarkPort,
|
||||
timerSupport[timerIdx].startMarkPin, GPIO_PIN_SET);
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[timerIdx].handle,
|
||||
timerSupport[timerIdx].channel,
|
||||
(uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
__HAL_TIM_ENABLE_IT(timerSupport[timerIdx].handle, TIM_IT_UPDATE);
|
||||
timerSupport[timerIdx].running = true;
|
||||
}
|
||||
uint8_t timerIdx = phaseOrder[phaseIdx];
|
||||
if (! timerSupport[timerIdx].running) {
|
||||
HAL_GPIO_WritePin(timerSupport[timerIdx].startMarkPort,
|
||||
timerSupport[timerIdx].startMarkPin, GPIO_PIN_SET);
|
||||
HAL_TIM_PWM_Start_DMA(timerSupport[timerIdx].handle, timerSupport[timerIdx].channel,
|
||||
(uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||
__HAL_TIM_ENABLE_IT(timerSupport[timerIdx].handle, TIM_IT_UPDATE);
|
||||
timerSupport[timerIdx].running = true;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++) {
|
||||
if (htim == timerSupport[i].handle) {
|
||||
timerSupport[i].slotCnt++;
|
||||
if (timerSupport[i].slotCnt == NUM_OF_SINE_SLOT + 3) {
|
||||
timerSupport[i].slotCnt = 3;
|
||||
HAL_GPIO_TogglePin(timerSupport[i].bridgePolarityPort,
|
||||
timerSupport[i].bridgePolarityPin);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++) {
|
||||
if (htim == timerSupport[i].handle) {
|
||||
timerSupport[i].slotCnt++;
|
||||
if (timerSupport[i].slotCnt == NUM_OF_SINE_SLOT + 2) {
|
||||
timerSupport[i].slotCnt = 2;
|
||||
HAL_GPIO_TogglePin(timerSupport[i].bridgePolarityPort, timerSupport[i].bridgePolarityPin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (htim == &htim1) {
|
||||
HAL_GPIO_TogglePin(Sync_GPIO_Port, Sync_Pin);
|
||||
if (htim == &htim1) {
|
||||
HAL_GPIO_TogglePin(Sync_GPIO_Port, Sync_Pin);
|
||||
|
||||
if (timer1Cnt == 0) {
|
||||
startPhase(0);
|
||||
} else if (timer1Cnt == ((NUM_OF_SINE_SLOT * 2) / 3)) {
|
||||
startPhase(1);
|
||||
} else if (timer1Cnt == ((NUM_OF_SINE_SLOT * 2) * 2 / 3)) {
|
||||
startPhase(2);
|
||||
}
|
||||
if (timer1Cnt == 0) {
|
||||
startPhase(0);
|
||||
} else if (timer1Cnt == ((NUM_OF_SINE_SLOT * 2) / 3)) {
|
||||
startPhase(1);
|
||||
} else if (timer1Cnt == ((NUM_OF_SINE_SLOT * 2) * 2 / 3)) {
|
||||
startPhase(2);
|
||||
}
|
||||
|
||||
timer1Cnt++;
|
||||
}
|
||||
timer1Cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,10 @@
|
||||
typedef enum { CLOCKWISE, COUNTERCLOCKWISE } direction_t;
|
||||
|
||||
void inverterBegin();
|
||||
void inverterStart(uint8_t freqOut, direction_t direction);
|
||||
void inverterStart(direction_t direction);
|
||||
void inverterStop();
|
||||
void inverterIncFrequency();
|
||||
void inverterDecFrequency();
|
||||
|
||||
|
||||
#endif /* INVERTER_H_ */
|
||||
|
@ -44,26 +44,13 @@ void my_errorHandler() {
|
||||
HAL_GPIO_WritePin(ERROR_PIN_GPIO_Port, ERROR_PIN_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void testSwitchFrequency1(void *handle) {
|
||||
inverterStart(100, CLOCKWISE);
|
||||
}
|
||||
void testSwitchFrequency2(void *handle) {
|
||||
inverterStart(50, CLOCKWISE);
|
||||
}
|
||||
|
||||
void testSwitchFrequency3(void *handle) {
|
||||
static uint8_t f = 1;
|
||||
inverterStart(f, CLOCKWISE);
|
||||
f++;
|
||||
void testSwitchFrequency(void *handle) {
|
||||
inverterIncFrequency();
|
||||
}
|
||||
void my_setup_2() {
|
||||
inverterBegin();
|
||||
|
||||
inverterStart(1, CLOCKWISE);
|
||||
// schAdd(testSwitchFrequency1, NULL, 5000, 0);
|
||||
// schAdd(testSwitchFrequency2, NULL, 10000, 0);
|
||||
// schAdd(testSwitchFrequency1, NULL, 15000, 0);
|
||||
schAdd(testSwitchFrequency3, NULL, 0, 1000);
|
||||
inverterStart(CLOCKWISE);
|
||||
schAdd(testSwitchFrequency, NULL, 0, 5000);
|
||||
}
|
||||
|
||||
|
||||
|
22
src/main.c
22
src/main.c
@ -212,21 +212,21 @@ static void MX_RTC_Init(void)
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
sTime.Hours = 0x1;
|
||||
sTime.Minutes = 0x0;
|
||||
sTime.Seconds = 0x0;
|
||||
sTime.Hours = 1;
|
||||
sTime.Minutes = 0;
|
||||
sTime.Seconds = 0;
|
||||
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
DateToUpdate.Month = RTC_MONTH_JANUARY;
|
||||
DateToUpdate.Date = 0x1;
|
||||
DateToUpdate.Year = 0x0;
|
||||
DateToUpdate.Date = 1;
|
||||
DateToUpdate.Year = 0;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
@ -241,7 +241,7 @@ static void MX_TIM1_Init(void)
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 36;
|
||||
htim1.Init.Prescaler = 72;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 5000;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -275,7 +275,7 @@ static void MX_TIM2_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 36;
|
||||
htim2.Init.Prescaler = 72;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 5000;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -324,7 +324,7 @@ static void MX_TIM4_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim4.Instance = TIM4;
|
||||
htim4.Init.Prescaler = 36;
|
||||
htim4.Init.Prescaler = 72;
|
||||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim4.Init.Period = 5000;
|
||||
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -373,7 +373,7 @@ static void MX_TIM5_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim5.Instance = TIM5;
|
||||
htim5.Init.Prescaler = 36;
|
||||
htim5.Init.Prescaler = 72;
|
||||
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim5.Init.Period = 5000;
|
||||
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
|
@ -208,21 +208,21 @@ static void MX_RTC_Init(void)
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
sTime.Hours = 0x1;
|
||||
sTime.Minutes = 0x0;
|
||||
sTime.Seconds = 0x0;
|
||||
sTime.Hours = 1;
|
||||
sTime.Minutes = 0;
|
||||
sTime.Seconds = 0;
|
||||
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
DateToUpdate.Month = RTC_MONTH_JANUARY;
|
||||
DateToUpdate.Date = 0x1;
|
||||
DateToUpdate.Year = 0x0;
|
||||
DateToUpdate.Date = 1;
|
||||
DateToUpdate.Year = 0;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
@ -237,7 +237,7 @@ static void MX_TIM1_Init(void)
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 36;
|
||||
htim1.Init.Prescaler = 72;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 5000;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -271,7 +271,7 @@ static void MX_TIM2_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 36;
|
||||
htim2.Init.Prescaler = 72;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 5000;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -320,7 +320,7 @@ static void MX_TIM4_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim4.Instance = TIM4;
|
||||
htim4.Init.Prescaler = 36;
|
||||
htim4.Init.Prescaler = 72;
|
||||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim4.Init.Period = 5000;
|
||||
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
@ -369,7 +369,7 @@ static void MX_TIM5_Init(void)
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim5.Instance = TIM5;
|
||||
htim5.Init.Prescaler = 36;
|
||||
htim5.Init.Prescaler = 72;
|
||||
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim5.Init.Period = 5000;
|
||||
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user