This commit is contained in:
DELL4 2023-03-01 19:50:06 +01:00
parent df732149dd
commit 2a360060dd
2 changed files with 27 additions and 29 deletions

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -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);