Hardware timer issue

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

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();
}

Where in your code is flashoff () called?

Hi mate in this iteration of the code it is not called because the code doesnt even get past flashon()
it compiles fine but led_builtin does not flash it just stays on as soon as i comment out the setmode line it flashes again as it should
flashoff works but it stops HIGH i need it to stop low
i can drive it LOW manually but it results in a brief flash which kinda bugs me although you cant see it on an incandesent bulb which is what it will be driving in service anyway
i probably should add i am using a stm32 f411 blackpill

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.