cannot set mode on hardware timer
Posted: Sat Oct 15, 2022 11:57 pm
Hi i am trying to write a simple code to flash an led on and off @ 1hz of which the stm32 example works fine
however when i pause the timer the pin stays high
i need it to stay low
when i try to change the timer channel with setmode the pin just goes high and stays there
any help would be greatly appreciated
/*
Timebase callback
This example shows how to configure HardwareTimer to execute a callback at regular interval.
Callback toggles pin.
Once configured, there is only CPU load for callbacks executions.
*/
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION < 0x01090000)
#error "Due to API change, this sketch is compatible with STM32_CORE_VERSION >= 0x01090000"
#endif
#if defined(LED_BUILTIN)
#define pin LED_BUILTIN
#else
#define pin PC13
#endif
#define channel 1
void Update_IT_callback(void)
{ // Toggle pin. 10hz toogle --> 5Hz PWM
digitalWrite(pin, !digitalRead(pin));
}
void setup()
{
pinMode(pin, OUTPUT);
flashon();
}
void loop()
{
/* Nothing to do all is done by hardware. Even no interrupt required. */
}
void flashon ()
{
TIM_TypeDef *Instance = TIM1;
HardwareTimer *MyTim = new HardwareTimer(Instance);
MyTim->setMode(channel, TIMER_OUTPUT_COMPARE_PWM2, pin);
MyTim->setOverflow(10, HERTZ_FORMAT); // 10 Hz
MyTim->attachInterrupt(Update_IT_callback);
MyTim->resume();
}
void flashoff ()
{
TIM_TypeDef *Instance = TIM1;
HardwareTimer *MyTim = new HardwareTimer(Instance);
MyTim->setMode(channel, TIMER_OUTPUT_COMPARE_PWM2, pin);
MyTim->setOverflow(10, HERTZ_FORMAT); // 10 Hz
MyTim->attachInterrupt(Update_IT_callback);
MyTim->pause();
}
however when i pause the timer the pin stays high
i need it to stay low
when i try to change the timer channel with setmode the pin just goes high and stays there
any help would be greatly appreciated
/*
Timebase callback
This example shows how to configure HardwareTimer to execute a callback at regular interval.
Callback toggles pin.
Once configured, there is only CPU load for callbacks executions.
*/
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION < 0x01090000)
#error "Due to API change, this sketch is compatible with STM32_CORE_VERSION >= 0x01090000"
#endif
#if defined(LED_BUILTIN)
#define pin LED_BUILTIN
#else
#define pin PC13
#endif
#define channel 1
void Update_IT_callback(void)
{ // Toggle pin. 10hz toogle --> 5Hz PWM
digitalWrite(pin, !digitalRead(pin));
}
void setup()
{
pinMode(pin, OUTPUT);
flashon();
}
void loop()
{
/* Nothing to do all is done by hardware. Even no interrupt required. */
}
void flashon ()
{
TIM_TypeDef *Instance = TIM1;
HardwareTimer *MyTim = new HardwareTimer(Instance);
MyTim->setMode(channel, TIMER_OUTPUT_COMPARE_PWM2, pin);
MyTim->setOverflow(10, HERTZ_FORMAT); // 10 Hz
MyTim->attachInterrupt(Update_IT_callback);
MyTim->resume();
}
void flashoff ()
{
TIM_TypeDef *Instance = TIM1;
HardwareTimer *MyTim = new HardwareTimer(Instance);
MyTim->setMode(channel, TIMER_OUTPUT_COMPARE_PWM2, pin);
MyTim->setOverflow(10, HERTZ_FORMAT); // 10 Hz
MyTim->attachInterrupt(Update_IT_callback);
MyTim->pause();
}