Compare commits
2 Commits
master
...
InFrequenc
Author | SHA1 | Date | |
---|---|---|---|
ef6c63b418 | |||
3b0e1cd72e |
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
|
||||
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;
|
||||
@ -49,8 +48,10 @@ volatile uint8_t phaseOrder[NUM_OF_TIMER];
|
||||
|
||||
void inverterBegin() {
|
||||
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
|
||||
float slotAngle = 180.0 / NUM_OF_SINE_SLOT;
|
||||
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;
|
||||
@ -62,6 +63,7 @@ void inverterBegin() {
|
||||
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;
|
||||
@ -72,6 +74,7 @@ void inverterBegin() {
|
||||
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;
|
||||
@ -82,15 +85,31 @@ void inverterBegin() {
|
||||
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();
|
||||
|
||||
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);
|
||||
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();
|
||||
|
||||
if (direction == CLOCKWISE) {
|
||||
phaseOrder[0] = 0;
|
||||
@ -107,12 +126,10 @@ void inverterStart(uint8_t freqOut, direction_t direction) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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, 5000);
|
||||
inverterStart(CLOCKWISE);
|
||||
schAdd(testSwitchFrequency, NULL, 0, 5000);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user