From 2a360060dd18fefa33fdb769ac2e4f4f05eba9da Mon Sep 17 00:00:00 2001 From: DELL4 Date: Wed, 1 Mar 2023 19:50:06 +0100 Subject: [PATCH] cleanup --- .idea/codeStyles/codeStyleConfig.xml | 5 +++ src/main.cpp | 51 ++++++++++++---------------- 2 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5c9a101..3fa0b6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,11 +5,11 @@ #define OUTPIN_N PB13 #define HVGENPIN PB9 -HardwareTimer *shockTimer; +HardwareTimer* shockTimer; uint32_t shockPwmChannel; uint32_t shockPwmChannel_N; -HardwareTimer *hvTimer; +HardwareTimer* hvTimer; uint32_t hvPwmChannel; uint32_t frequency = 50; @@ -18,6 +18,7 @@ uint8_t deadTime = 50; uint32_t hvFrequency = 250000; uint8_t hvDutyCycle = 61; + /** * output = red, green jumper wire * input = yellow @@ -25,26 +26,26 @@ uint8_t hvDutyCycle = 61; */ void setup(void) { - pinMode(PA0, INPUT_ANALOG); - pinMode(LED_BUILTIN, OUTPUT); + pinMode(PA0, INPUT_ANALOG); + pinMode(LED_BUILTIN, OUTPUT); - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; + TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; - // https://github.com/ahmetonat/STM32F103-ADC-DMA-example/blob/master/Src/stm32f1xx_hal_msp.c - // https://www.stm32duino.com/viewtopic.php?f=41&t=110 - // https://controllerstech.com/dma-with-adc-using-registers-in-stm32/ - // https://stm32duinoforum.com/forum/viewtopic_f_48_t_4399.html + // https://github.com/ahmetonat/STM32F103-ADC-DMA-example/blob/master/Src/stm32f1xx_hal_msp.c + // https://www.stm32duino.com/viewtopic.php?f=41&t=110 + // https://controllerstech.com/dma-with-adc-using-registers-in-stm32/ + // https://stm32duinoforum.com/forum/viewtopic_f_48_t_4399.html - TIM_TypeDef *shockInstance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(OUTPIN), PinMap_PWM); + TIM_TypeDef* shockInstance = (TIM_TypeDef*) pinmap_peripheral(digitalPinToPinName(OUTPIN), PinMap_PWM); shockPwmChannel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(OUTPIN), PinMap_PWM)); shockPwmChannel_N = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(OUTPIN_N), PinMap_PWM)); shockTimer = new HardwareTimer(shockInstance); - TIM_TypeDef *hvInstance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(HVGENPIN), PinMap_PWM); + TIM_TypeDef* hvInstance = (TIM_TypeDef*) pinmap_peripheral(digitalPinToPinName(HVGENPIN), PinMap_PWM); hvPwmChannel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(HVGENPIN), PinMap_PWM)); hvTimer = new HardwareTimer(hvInstance); // hvTimer->getHandle()->Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED3; - hvTimer->setPWM(hvPwmChannel, HVGENPIN, hvFrequency, hvDutyCycle); + hvTimer->setPWM(hvPwmChannel, HVGENPIN, hvFrequency, hvDutyCycle); Serial.begin(0); @@ -57,7 +58,7 @@ void setup(void) { shockTimer->setMode(shockPwmChannel_N, TIMER_OUTPUT_COMPARE_PWM1, OUTPIN_N); shockTimer->setPWM(shockPwmChannel, OUTPIN, frequency, dutyCycle); - TIM1->CCER |= TIM_CCER_CC1NE; // Enable time r1 complementare output (channel 1) + TIM1->CCER |= TIM_CCER_CC1NE; // Enable timer 1 complementary output (channel 1) sBreakDeadTimeConfig.BreakState = TIM_BREAK_ENABLE; sBreakDeadTimeConfig.DeadTime = deadTime; @@ -70,22 +71,16 @@ void setup(void) { // LL_TIM_OC_SetDeadTime(TIM1, 50); // shockInstance->BDTR |= 0xFF; - // with register manipulation, approx 14ns per increment 0 to 128 - // (DTG Bits 7:0) -> DGT Bit 2|5 = 00100100 = 560ns - // bitSet(TIMER1_BASE->BDTR, 2); - // bitSet(TIMER1_BASE->BDTR, 5); - - // shockTimer->setPWM(shockPwmChannel, OUTPIN_N, frequency, dutyCycle); - // shockTimer->setPWM(shockPwmChannel, OUTPIN_N, frequency, dutyCycle); - // setMode(shockPwmChannel, TIMER_, pin); + // deadtime with register manipulation, approx 14ns per increment 0 to 128 + // (DTG Bits 7:0) -> DGT Bit 2|5 = 00100100 = 560ns + // bitSet(TIMER1_BASE->BDTR, 2); + // bitSet(TIMER1_BASE->BDTR, 5); /* shockTimer->pause(); + // complementary PWM with direct register manipulation // TIM1->CCER |= 0x555; //3ch compl enable. 0x55 = 2ch compl enable. 0x5 = 1ch compl enable. As seen on RM0008 pages 353 & 354, CCxNE and CCxE bits TIM1->CCER &= ~TIM_CCER_CC1NP; -- polarity low (or |= to high) - TIM1->CCER |= TIM_OCNPOLARITY_HIGH; - TIM1->CCER |= 0; - TIM1->CCER |= 2; - TIM1->CCER |= TIM_CCER_CC1NE; + TIM1->CCER |= TIM_OCNPOLARITY_HIGH | 2 | TIM_CCER_CC1NE; TIM1->CR1 |= TIM_CR1_CMS_1; // center waveform shockTimer->resume(); */ @@ -132,7 +127,7 @@ uint32_t getRegister(uint8_t reg) { return deadTime; } - return -1; + return -1; } void processSerial() { @@ -153,11 +148,9 @@ void processSerial() { // get register uint8_t reg = Serial.read(); uint32_t val = getRegister(reg); - // Serial.write((uint8_t*) &val, sizeof(val)); Serial.write((uint8_t*) &val, sizeof(val)); - // Serial.write((uint8_t*) &val, sizeof(val)); - // uint32_t val = getRegister(reg); } else { + // error, blink the LED for (int i = 0; i < 5; i++) { digitalWrite(LED_BUILTIN, HIGH); delay(100);