From 677d882bbb158cf471617b6f51bbaebc8397fea8 Mon Sep 17 00:00:00 2001 From: zaubentrucker Date: Mon, 23 Dec 2024 14:07:54 +0100 Subject: [PATCH] Set proper prescaler and period for 100Hz --- red/mod-io2/src/main.cpp | 7 ++++++- red/mod-io2/src/mod_io2.cpp | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/red/mod-io2/src/main.cpp b/red/mod-io2/src/main.cpp index 318f72f..baa1c0a 100644 --- a/red/mod-io2/src/main.cpp +++ b/red/mod-io2/src/main.cpp @@ -1,3 +1,4 @@ +#include #if defined(CH32V00X) #include #elif defined(CH32V10X) @@ -59,17 +60,21 @@ int main(void) { MOD_IO2::Setup(); - bool should_blink = true; + bool should_blink = false; + TIM_TimeBaseInitTypeDef TimerConfig; while (1) { Wait_Ms(1000); + printf("sizeof(TimerConfig.TIM_Period): %lu \r\n", sizeof(TimerConfig.TIM_Period)); printf("-DEBUG-PR-%08x\r\n", i++); if(should_blink) { MOD_IO2::onRegisterSet(0x41); MOD_IO2::onRegWrite(0x41, 0, 3); // MOD_IO2::onRelayOn(0x40, 0, 0x03); } + MOD_IO2::onRegisterSet(0x51); + MOD_IO2::onRegWrite(0x51, 0, 255); Wait_Ms(1000); printf("-DEBUG-PR-%08x\r\n", i++); diff --git a/red/mod-io2/src/mod_io2.cpp b/red/mod-io2/src/mod_io2.cpp index ba08214..87063a6 100644 --- a/red/mod-io2/src/mod_io2.cpp +++ b/red/mod-io2/src/mod_io2.cpp @@ -390,14 +390,14 @@ void MOD_IO2::PWMConfig(TIM_TypeDef *TIM, uint8_t channel, uint16_t pulse) { TIM_CtrlPWMOutputs(TIM, DISABLE); TIM_TimeBaseInitTypeDef TimerConfig; - TimerConfig.TIM_Period = 255; - TimerConfig.TIM_Prescaler = 608; + TimerConfig.TIM_Period = 65535; + TimerConfig.TIM_Prescaler = 6; TimerConfig.TIM_CounterMode = TIM_CounterMode_Up; TimerConfig.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInit(TIM, &TimerConfig); TIM_OCInitTypeDef TIM_OCConfig={0}; - TIM_OCConfig.TIM_Pulse = pulse; + TIM_OCConfig.TIM_Pulse = 6553; TIM_OCConfig.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCConfig.TIM_OutputState = TIM_OutputState_Enable; TIM_OCConfig.TIM_OCPolarity = TIM_OCPolarity_High;