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

@ -18,6 +18,7 @@ uint8_t deadTime = 50;
uint32_t hvFrequency = 250000; uint32_t hvFrequency = 250000;
uint8_t hvDutyCycle = 61; uint8_t hvDutyCycle = 61;
/** /**
* output = red, green jumper wire * output = red, green jumper wire
* input = yellow * input = yellow
@ -57,7 +58,7 @@ void setup(void) {
shockTimer->setMode(shockPwmChannel_N, TIMER_OUTPUT_COMPARE_PWM1, OUTPIN_N); shockTimer->setMode(shockPwmChannel_N, TIMER_OUTPUT_COMPARE_PWM1, OUTPIN_N);
shockTimer->setPWM(shockPwmChannel, OUTPIN, frequency, dutyCycle); 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.BreakState = TIM_BREAK_ENABLE;
sBreakDeadTimeConfig.DeadTime = deadTime; sBreakDeadTimeConfig.DeadTime = deadTime;
@ -70,22 +71,16 @@ void setup(void) {
// LL_TIM_OC_SetDeadTime(TIM1, 50); // LL_TIM_OC_SetDeadTime(TIM1, 50);
// shockInstance->BDTR |= 0xFF; // shockInstance->BDTR |= 0xFF;
// with register manipulation, approx 14ns per increment 0 to 128 // deadtime with register manipulation, approx 14ns per increment 0 to 128
// (DTG Bits 7:0) -> DGT Bit 2|5 = 00100100 = 560ns // (DTG Bits 7:0) -> DGT Bit 2|5 = 00100100 = 560ns
// bitSet(TIMER1_BASE->BDTR, 2); // bitSet(TIMER1_BASE->BDTR, 2);
// bitSet(TIMER1_BASE->BDTR, 5); // bitSet(TIMER1_BASE->BDTR, 5);
// shockTimer->setPWM(shockPwmChannel, OUTPIN_N, frequency, dutyCycle);
// shockTimer->setPWM(shockPwmChannel, OUTPIN_N, frequency, dutyCycle);
// setMode(shockPwmChannel, TIMER_, pin);
/* shockTimer->pause(); /* 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 |= 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_CCER_CC1NP; -- polarity low (or |= to high)
TIM1->CCER |= TIM_OCNPOLARITY_HIGH; TIM1->CCER |= TIM_OCNPOLARITY_HIGH | 2 | TIM_CCER_CC1NE;
TIM1->CCER |= 0;
TIM1->CCER |= 2;
TIM1->CCER |= TIM_CCER_CC1NE;
TIM1->CR1 |= TIM_CR1_CMS_1; // center waveform TIM1->CR1 |= TIM_CR1_CMS_1; // center waveform
shockTimer->resume(); */ shockTimer->resume(); */
@ -153,11 +148,9 @@ void processSerial() {
// get register // get register
uint8_t reg = Serial.read(); uint8_t reg = Serial.read();
uint32_t val = getRegister(reg); 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));
// Serial.write((uint8_t*) &val, sizeof(val));
// uint32_t val = getRegister(reg);
} else { } else {
// error, blink the LED
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
delay(100); delay(100);