Set proper prescaler and period for 100Hz

This commit is contained in:
zaubentrucker 2024-12-23 14:07:54 +01:00
parent 55ffaf10fa
commit 677d882bbb
2 changed files with 9 additions and 4 deletions

View file

@ -1,3 +1,4 @@
#include <cstdio>
#if defined(CH32V00X) #if defined(CH32V00X)
#include <ch32v00x.h> #include <ch32v00x.h>
#elif defined(CH32V10X) #elif defined(CH32V10X)
@ -59,17 +60,21 @@ int main(void) {
MOD_IO2::Setup(); MOD_IO2::Setup();
bool should_blink = true; bool should_blink = false;
TIM_TimeBaseInitTypeDef TimerConfig;
while (1) while (1)
{ {
Wait_Ms(1000); Wait_Ms(1000);
printf("sizeof(TimerConfig.TIM_Period): %lu \r\n", sizeof(TimerConfig.TIM_Period));
printf("-DEBUG-PR-%08x\r\n", i++); printf("-DEBUG-PR-%08x\r\n", i++);
if(should_blink) { if(should_blink) {
MOD_IO2::onRegisterSet(0x41); MOD_IO2::onRegisterSet(0x41);
MOD_IO2::onRegWrite(0x41, 0, 3); MOD_IO2::onRegWrite(0x41, 0, 3);
// MOD_IO2::onRelayOn(0x40, 0, 0x03); // MOD_IO2::onRelayOn(0x40, 0, 0x03);
} }
MOD_IO2::onRegisterSet(0x51);
MOD_IO2::onRegWrite(0x51, 0, 255);
Wait_Ms(1000); Wait_Ms(1000);
printf("-DEBUG-PR-%08x\r\n", i++); printf("-DEBUG-PR-%08x\r\n", i++);

View file

@ -390,14 +390,14 @@ void MOD_IO2::PWMConfig(TIM_TypeDef *TIM, uint8_t channel, uint16_t pulse) {
TIM_CtrlPWMOutputs(TIM, DISABLE); TIM_CtrlPWMOutputs(TIM, DISABLE);
TIM_TimeBaseInitTypeDef TimerConfig; TIM_TimeBaseInitTypeDef TimerConfig;
TimerConfig.TIM_Period = 255; TimerConfig.TIM_Period = 65535;
TimerConfig.TIM_Prescaler = 608; TimerConfig.TIM_Prescaler = 6;
TimerConfig.TIM_CounterMode = TIM_CounterMode_Up; TimerConfig.TIM_CounterMode = TIM_CounterMode_Up;
TimerConfig.TIM_ClockDivision = TIM_CKD_DIV1; TimerConfig.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM, &TimerConfig); TIM_TimeBaseInit(TIM, &TimerConfig);
TIM_OCInitTypeDef TIM_OCConfig={0}; 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_OCMode = TIM_OCMode_PWM1;
TIM_OCConfig.TIM_OutputState = TIM_OutputState_Enable; TIM_OCConfig.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCConfig.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCConfig.TIM_OCPolarity = TIM_OCPolarity_High;