I want to config timer1 as a 60kHz pulse and timer2 as 15kHz.My code is as follow.
I’ve simulated it in Proteus. Each timer work correctly alone but when two timer is running it doesn’t work correct.
My code:
#define pin PC13
#define pin2 PC14
bool status = false;
TIM_TypeDef *Instance = TIM1;
TIM_TypeDef *Instance_2 = TIM2;
HardwareTimer *MyTim = new HardwareTimer(Instance);
HardwareTimer *MyTim_2 = new HardwareTimer(Instance_2);
//*********************************************************************************
void setup() {
// configure pin in output mode
pinMode(pin, OUTPUT);
pinMode(pin2, OUTPUT);
digitalWrite(pin2,LOW);
MyTim->setOverflow(120000, HERTZ_FORMAT); // 60 kHz
MyTim->attachInterrupt(Update_IT_callback);
MyTim->resume();
MyTim_2->setOverflow(30000, HERTZ_FORMAT); // 15 kHz
MyTim_2->attachInterrupt(Update_IT_callback_2);
MyTim_2->resume();
}
void loop()
{
/* Nothing to do all is done by hardware. Even no interrupt required. */
}
void Update_IT_callback(void)
{
status = !status;
digitalWrite(pin, status ? HIGH : LOW);
}
void Update_IT_callback_2(void)
{
status = !status;
digitalWrite(pin2, status ? HIGH : LOW)
}
T1: timer1 as 60kHz and T2: timer2 as 15kHz.
As you see in the image, T1 doesn’t work correctly.
could you tell what is my mistake please?