fix double freq issue and play around with resolution

This commit is contained in:
Wolfgang Hottgenroth
2016-11-14 15:44:36 +01:00
parent f12f95c565
commit 2b9287bc21
8 changed files with 76 additions and 68 deletions

View File

@ -6,6 +6,10 @@
*/
#ifdef SEMIHOSTING_ENABLED
#include <diag/Trace.h>
#endif
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
@ -20,8 +24,8 @@ extern TIM_HandleTypeDef htim4;
extern TIM_HandleTypeDef htim5;
#define NUM_OF_SINE_SLOT 30
const uint32_t FREQ_IN = 1E6;
#define NUM_OF_SINE_SLOT 60
const uint32_t FREQ_IN = 2E6;
const float PI = 3.14159;
float slotAngle = 180.0 / NUM_OF_SINE_SLOT;
float sineValues[NUM_OF_SINE_SLOT];
@ -87,7 +91,12 @@ void inverterBegin() {
void inverterStart(uint8_t freqOut, direction_t direction) {
inverterStop();
uint16_t slotWidth = (FREQ_IN / (freqOut * NUM_OF_SINE_SLOT * 4));
uint16_t slotWidth = (FREQ_IN / (freqOut * NUM_OF_SINE_SLOT * 2));
#ifdef SEMIHOSTING_ENABLE
trace_printf("slotWidth: %d\n", slotWidth);
#endif
for (uint8_t i = 0; i < NUM_OF_SINE_SLOT; i++) {
IV[i] = (uint16_t)(sineValues[i] * 0.9 * slotWidth);
}
@ -149,8 +158,8 @@ 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 + 2) {
timerSupport[i].slotCnt = 2;
if (timerSupport[i].slotCnt == NUM_OF_SINE_SLOT + 3) {
timerSupport[i].slotCnt = 3;
HAL_GPIO_TogglePin(timerSupport[i].bridgePolarityPort,
timerSupport[i].bridgePolarityPin);
}

View File

@ -59,7 +59,7 @@ void testSwitchFrequency3(void *handle) {
void my_setup_2() {
inverterBegin();
inverterStart(25, CLOCKWISE);
inverterStart(100, CLOCKWISE);
// schAdd(testSwitchFrequency1, NULL, 5000, 0);
// schAdd(testSwitchFrequency2, NULL, 10000, 0);
// schAdd(testSwitchFrequency1, NULL, 15000, 0);