Compare commits
2 Commits
TimerResta
...
InFrequenc
Author | SHA1 | Date | |
---|---|---|---|
ef6c63b418 | |||
3b0e1cd72e |
@ -5,7 +5,7 @@ SourcePath=/home/wn/workspace-stm32/inverter2/cubemx/output/inverter2/Src
|
|||||||
SourceFiles=stm32f1xx_it.h;stm32f1xx_hal_conf.h;mxconstants.h;stm32f1xx_it.c;stm32f1xx_hal_msp.c;main.c;
|
SourceFiles=stm32f1xx_it.h;stm32f1xx_hal_conf.h;mxconstants.h;stm32f1xx_it.c;stm32f1xx_hal_msp.c;main.c;
|
||||||
|
|
||||||
[PreviousLibFiles]
|
[PreviousLibFiles]
|
||||||
LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_can.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_can_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rtc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rtc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_can.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/cmsis_armcc_V6.h;Drivers/CMSIS/Include/core_cmFunc.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/arm_common_tables.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/core_cmInstr.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/arm_math.h;Drivers/CMSIS/Include/arm_const_structs.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_cmSimd.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xg.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101x6.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f107xc.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102x6.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xg.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f105xc.h;
|
LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_can.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_can_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rtc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rtc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_can.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/cmsis_armcc_V6.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/arm_const_structs.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cmSimd.h;Drivers/CMSIS/Include/core_cmFunc.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/arm_common_tables.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/arm_math.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cmInstr.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101x6.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xg.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102x6.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f105xc.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xg.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f107xc.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h;
|
||||||
|
|
||||||
[PreviousUsedRideFiles]
|
[PreviousUsedRideFiles]
|
||||||
SourceFiles=../Src/main.c;../Src/stm32f1xx_it.c;../Src/stm32f1xx_hal_msp.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_can.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;../Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;../Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103xe.s;
|
SourceFiles=../Src/main.c;../Src/stm32f1xx_it.c;../Src/stm32f1xx_hal_msp.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_can.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;../Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;../Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103xe.s;
|
||||||
|
@ -3,27 +3,27 @@ CAN.CalculateTimeBit=1333
|
|||||||
CAN.CalculateTimeQuantum=444.44444444444446
|
CAN.CalculateTimeQuantum=444.44444444444446
|
||||||
CAN.IPParameters=CalculateTimeQuantum,CalculateTimeBit
|
CAN.IPParameters=CalculateTimeQuantum,CalculateTimeBit
|
||||||
Dma.Request0=TIM5_CH2
|
Dma.Request0=TIM5_CH2
|
||||||
Dma.Request1=TIM4_CH1
|
Dma.Request1=TIM2_CH1
|
||||||
Dma.Request2=TIM2_CH1
|
Dma.Request2=TIM4_CH1
|
||||||
Dma.RequestsNb=3
|
Dma.RequestsNb=3
|
||||||
Dma.TIM2_CH1.2.Direction=DMA_MEMORY_TO_PERIPH
|
Dma.TIM2_CH1.1.Direction=DMA_MEMORY_TO_PERIPH
|
||||||
Dma.TIM2_CH1.2.Instance=DMA1_Channel5
|
Dma.TIM2_CH1.1.Instance=DMA1_Channel5
|
||||||
Dma.TIM2_CH1.2.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
|
Dma.TIM2_CH1.1.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
|
||||||
Dma.TIM2_CH1.2.MemInc=DMA_MINC_ENABLE
|
Dma.TIM2_CH1.1.MemInc=DMA_MINC_ENABLE
|
||||||
Dma.TIM2_CH1.2.Mode=DMA_CIRCULAR
|
Dma.TIM2_CH1.1.Mode=DMA_CIRCULAR
|
||||||
Dma.TIM2_CH1.2.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
|
Dma.TIM2_CH1.1.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
|
||||||
Dma.TIM2_CH1.2.PeriphInc=DMA_PINC_DISABLE
|
Dma.TIM2_CH1.1.PeriphInc=DMA_PINC_DISABLE
|
||||||
Dma.TIM2_CH1.2.Priority=DMA_PRIORITY_LOW
|
Dma.TIM2_CH1.1.Priority=DMA_PRIORITY_LOW
|
||||||
Dma.TIM2_CH1.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
Dma.TIM2_CH1.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
||||||
Dma.TIM4_CH1.1.Direction=DMA_MEMORY_TO_PERIPH
|
Dma.TIM4_CH1.2.Direction=DMA_MEMORY_TO_PERIPH
|
||||||
Dma.TIM4_CH1.1.Instance=DMA1_Channel1
|
Dma.TIM4_CH1.2.Instance=DMA1_Channel1
|
||||||
Dma.TIM4_CH1.1.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
|
Dma.TIM4_CH1.2.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
|
||||||
Dma.TIM4_CH1.1.MemInc=DMA_MINC_ENABLE
|
Dma.TIM4_CH1.2.MemInc=DMA_MINC_ENABLE
|
||||||
Dma.TIM4_CH1.1.Mode=DMA_CIRCULAR
|
Dma.TIM4_CH1.2.Mode=DMA_CIRCULAR
|
||||||
Dma.TIM4_CH1.1.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
|
Dma.TIM4_CH1.2.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
|
||||||
Dma.TIM4_CH1.1.PeriphInc=DMA_PINC_DISABLE
|
Dma.TIM4_CH1.2.PeriphInc=DMA_PINC_DISABLE
|
||||||
Dma.TIM4_CH1.1.Priority=DMA_PRIORITY_LOW
|
Dma.TIM4_CH1.2.Priority=DMA_PRIORITY_LOW
|
||||||
Dma.TIM4_CH1.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
Dma.TIM4_CH1.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
||||||
Dma.TIM5_CH2.0.Direction=DMA_MEMORY_TO_PERIPH
|
Dma.TIM5_CH2.0.Direction=DMA_MEMORY_TO_PERIPH
|
||||||
Dma.TIM5_CH2.0.Instance=DMA2_Channel4
|
Dma.TIM5_CH2.0.Instance=DMA2_Channel4
|
||||||
Dma.TIM5_CH2.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
|
Dma.TIM5_CH2.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
|
||||||
|
BIN
doc/InFrequencyShifting.xlsx
Normal file
BIN
doc/InFrequencyShifting.xlsx
Normal file
Binary file not shown.
@ -21,10 +21,9 @@ extern TIM_HandleTypeDef htim5;
|
|||||||
|
|
||||||
|
|
||||||
#define NUM_OF_SINE_SLOT 30
|
#define NUM_OF_SINE_SLOT 30
|
||||||
|
const uint32_t SLOT_WIDTH = 1500;
|
||||||
const uint32_t FREQ_IN = 1E6;
|
const uint32_t FREQ_IN = 1E6;
|
||||||
const float PI = 3.14159;
|
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];
|
uint16_t IV[NUM_OF_SINE_SLOT];
|
||||||
|
|
||||||
volatile uint32_t timer1Cnt;
|
volatile uint32_t timer1Cnt;
|
||||||
@ -49,8 +48,10 @@ volatile uint8_t phaseOrder[NUM_OF_TIMER];
|
|||||||
|
|
||||||
void inverterBegin() {
|
void inverterBegin() {
|
||||||
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
|
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
|
||||||
|
float slotAngle = 180.0 / NUM_OF_SINE_SLOT;
|
||||||
float angle = i * slotAngle;
|
float angle = i * slotAngle;
|
||||||
sineValues[i] = sinf(angle / 180 * PI);
|
float sineValues = sinf(angle / 180 * PI);
|
||||||
|
IV[i] = (uint16_t)(sineValues[i] * 0.9 * SLOT_WIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
timerSupport[0].handle = &htim2;
|
timerSupport[0].handle = &htim2;
|
||||||
@ -62,6 +63,7 @@ void inverterBegin() {
|
|||||||
timerSupport[0].channel = TIM_CHANNEL_1;
|
timerSupport[0].channel = TIM_CHANNEL_1;
|
||||||
timerSupport[0].startMarkPort = LED0_GPIO_Port;
|
timerSupport[0].startMarkPort = LED0_GPIO_Port;
|
||||||
timerSupport[0].startMarkPin = LED0_Pin;
|
timerSupport[0].startMarkPin = LED0_Pin;
|
||||||
|
__HAL_TIM_SET_AUTORELOAD(timerSupport[0].handle, SLOT_WIDTH);
|
||||||
|
|
||||||
timerSupport[1].handle = &htim5;
|
timerSupport[1].handle = &htim5;
|
||||||
timerSupport[1].running = false;
|
timerSupport[1].running = false;
|
||||||
@ -72,6 +74,7 @@ void inverterBegin() {
|
|||||||
timerSupport[1].channel = TIM_CHANNEL_2;
|
timerSupport[1].channel = TIM_CHANNEL_2;
|
||||||
timerSupport[1].startMarkPort = LED1_GPIO_Port;
|
timerSupport[1].startMarkPort = LED1_GPIO_Port;
|
||||||
timerSupport[1].startMarkPin = LED1_Pin;
|
timerSupport[1].startMarkPin = LED1_Pin;
|
||||||
|
__HAL_TIM_SET_AUTORELOAD(timerSupport[1].handle, SLOT_WIDTH);
|
||||||
|
|
||||||
timerSupport[2].handle = &htim4;
|
timerSupport[2].handle = &htim4;
|
||||||
timerSupport[2].running = false;
|
timerSupport[2].running = false;
|
||||||
@ -82,16 +85,32 @@ void inverterBegin() {
|
|||||||
timerSupport[2].channel = TIM_CHANNEL_1;
|
timerSupport[2].channel = TIM_CHANNEL_1;
|
||||||
timerSupport[2].startMarkPort = LED2_GPIO_Port;
|
timerSupport[2].startMarkPort = LED2_GPIO_Port;
|
||||||
timerSupport[2].startMarkPin = LED2_Pin;
|
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) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void inverterStart(direction_t direction) {
|
||||||
inverterStop();
|
inverterStop();
|
||||||
|
|
||||||
uint16_t slotWidth = (FREQ_IN / (freqOut * NUM_OF_SINE_SLOT * 4));
|
|
||||||
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
|
|
||||||
IV[i] = (uint16_t)(sineValues[i] * 0.9 * slotWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == CLOCKWISE) {
|
if (direction == CLOCKWISE) {
|
||||||
phaseOrder[0] = 0;
|
phaseOrder[0] = 0;
|
||||||
phaseOrder[1] = 1;
|
phaseOrder[1] = 1;
|
||||||
@ -106,14 +125,11 @@ void inverterStart(uint8_t freqOut, direction_t direction) {
|
|||||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
||||||
timerSupport[i].slotCnt = 0;
|
timerSupport[i].slotCnt = 0;
|
||||||
timerSupport[i].running = false;
|
timerSupport[i].running = false;
|
||||||
HAL_GPIO_WritePin(timerSupport[i].bridgePolarityPort,
|
HAL_GPIO_WritePin(timerSupport[i].bridgePolarityPort, timerSupport[i].bridgePolarityPin, GPIO_PIN_RESET);
|
||||||
timerSupport[i].bridgePolarityPin, GPIO_PIN_RESET);
|
|
||||||
__HAL_TIM_SET_AUTORELOAD(timerSupport[i].handle, slotWidth);
|
|
||||||
__HAL_TIM_SET_COUNTER(timerSupport[i].handle, 0);
|
__HAL_TIM_SET_COUNTER(timerSupport[i].handle, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer1Cnt = 0;
|
timer1Cnt = 0;
|
||||||
__HAL_TIM_SET_AUTORELOAD(&htim1, slotWidth);
|
|
||||||
__HAL_TIM_SET_COUNTER(&htim1, 0);
|
__HAL_TIM_SET_COUNTER(&htim1, 0);
|
||||||
HAL_TIM_Base_Start_IT(&htim1);
|
HAL_TIM_Base_Start_IT(&htim1);
|
||||||
__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE);
|
__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE);
|
||||||
@ -126,8 +142,7 @@ void inverterStop() {
|
|||||||
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
for (uint8_t i = 0; i < NUM_OF_TIMER; i++){
|
||||||
HAL_TIM_PWM_Stop_DMA(timerSupport[i].handle, timerSupport[i].channel);
|
HAL_TIM_PWM_Stop_DMA(timerSupport[i].handle, timerSupport[i].channel);
|
||||||
__HAL_TIM_DISABLE_IT(timerSupport[i].handle, TIM_IT_UPDATE);
|
__HAL_TIM_DISABLE_IT(timerSupport[i].handle, TIM_IT_UPDATE);
|
||||||
HAL_GPIO_WritePin(timerSupport[i].startMarkPort,
|
HAL_GPIO_WritePin(timerSupport[i].startMarkPort, timerSupport[i].startMarkPin, GPIO_PIN_RESET);
|
||||||
timerSupport[i].startMarkPin, GPIO_PIN_RESET);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,8 +152,7 @@ static void startPhase(uint8_t phaseIdx) {
|
|||||||
if (! timerSupport[timerIdx].running) {
|
if (! timerSupport[timerIdx].running) {
|
||||||
HAL_GPIO_WritePin(timerSupport[timerIdx].startMarkPort,
|
HAL_GPIO_WritePin(timerSupport[timerIdx].startMarkPort,
|
||||||
timerSupport[timerIdx].startMarkPin, GPIO_PIN_SET);
|
timerSupport[timerIdx].startMarkPin, GPIO_PIN_SET);
|
||||||
HAL_TIM_PWM_Start_DMA(timerSupport[timerIdx].handle,
|
HAL_TIM_PWM_Start_DMA(timerSupport[timerIdx].handle, timerSupport[timerIdx].channel,
|
||||||
timerSupport[timerIdx].channel,
|
|
||||||
(uint32_t*)IV, NUM_OF_SINE_SLOT);
|
(uint32_t*)IV, NUM_OF_SINE_SLOT);
|
||||||
__HAL_TIM_ENABLE_IT(timerSupport[timerIdx].handle, TIM_IT_UPDATE);
|
__HAL_TIM_ENABLE_IT(timerSupport[timerIdx].handle, TIM_IT_UPDATE);
|
||||||
timerSupport[timerIdx].running = true;
|
timerSupport[timerIdx].running = true;
|
||||||
@ -151,8 +165,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
|||||||
timerSupport[i].slotCnt++;
|
timerSupport[i].slotCnt++;
|
||||||
if (timerSupport[i].slotCnt == NUM_OF_SINE_SLOT + 2) {
|
if (timerSupport[i].slotCnt == NUM_OF_SINE_SLOT + 2) {
|
||||||
timerSupport[i].slotCnt = 2;
|
timerSupport[i].slotCnt = 2;
|
||||||
HAL_GPIO_TogglePin(timerSupport[i].bridgePolarityPort,
|
HAL_GPIO_TogglePin(timerSupport[i].bridgePolarityPort, timerSupport[i].bridgePolarityPin);
|
||||||
timerSupport[i].bridgePolarityPin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
typedef enum { CLOCKWISE, COUNTERCLOCKWISE } direction_t;
|
typedef enum { CLOCKWISE, COUNTERCLOCKWISE } direction_t;
|
||||||
|
|
||||||
void inverterBegin();
|
void inverterBegin();
|
||||||
void inverterStart(uint8_t freqOut, direction_t direction);
|
void inverterStart(direction_t direction);
|
||||||
void inverterStop();
|
void inverterStop();
|
||||||
|
void inverterIncFrequency();
|
||||||
|
void inverterDecFrequency();
|
||||||
|
|
||||||
|
|
||||||
#endif /* INVERTER_H_ */
|
#endif /* INVERTER_H_ */
|
||||||
|
@ -44,26 +44,13 @@ void my_errorHandler() {
|
|||||||
HAL_GPIO_WritePin(ERROR_PIN_GPIO_Port, ERROR_PIN_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(ERROR_PIN_GPIO_Port, ERROR_PIN_Pin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testSwitchFrequency1(void *handle) {
|
void testSwitchFrequency(void *handle) {
|
||||||
inverterStart(100, CLOCKWISE);
|
inverterIncFrequency();
|
||||||
}
|
|
||||||
void testSwitchFrequency2(void *handle) {
|
|
||||||
inverterStart(50, CLOCKWISE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testSwitchFrequency3(void *handle) {
|
|
||||||
static uint8_t f = 1;
|
|
||||||
inverterStart(f, CLOCKWISE);
|
|
||||||
f++;
|
|
||||||
}
|
}
|
||||||
void my_setup_2() {
|
void my_setup_2() {
|
||||||
inverterBegin();
|
inverterBegin();
|
||||||
|
inverterStart(CLOCKWISE);
|
||||||
inverterStart(25, CLOCKWISE);
|
schAdd(testSwitchFrequency, NULL, 0, 5000);
|
||||||
// schAdd(testSwitchFrequency1, NULL, 5000, 0);
|
|
||||||
// schAdd(testSwitchFrequency2, NULL, 10000, 0);
|
|
||||||
// schAdd(testSwitchFrequency1, NULL, 15000, 0);
|
|
||||||
// schAdd(testSwitchFrequency3, NULL, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user