2016-12-14 04:59 AM
Hello everybody
I am using stm32f030F4 in my project and i need a timer with frequency 200kHz
I set timer1 for this frequency and toggled a pin in timer callback function and watch with oscilloscope
i can see a signal with frequency 100kHz this is ok so far but when i made some additional operations like toggle another pin the interrupt frequency speed droping about 4kHz if i add one more toggling it is dropping about 40kHz
And i tried to make it with flag and do the operations in while loop but it is also droping so i cant make the system work stable.
i am using stmcubemx to create project and i set timer and others clock 48 MHz
my timer configuration is like that:
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 239; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim1.Init.RepetitionCounter = 0;I really need your helps.
Maybe i am missing somewhere because when i look datasheet i see it need to work.
thanks for your helps
#hal #frequency #timer #clock #stm32f0Solved! Go to Solution.
2016-12-15 12:08 AM
Try using the DMA memory to gpio instead. You can trigger DMA channel 2,3,4 and 5 on TIM1 channels. So you can attach circular memory to the BSRR registers for 64 gpio's.
Or
Try using only writes to BSRR in an assembly written isr. That way you don't have to stack as much registers.
(only 2, iirc)
Also see bitbanding, so you don't have to shift.
You're looking to do things that are not compatible with arduino level software architecture.
2016-12-14 09:14 AM
Some extra info would be needed to understand if the interrupt is longer than the timer overlow time. Sometime, depending on what is really needed, maybe a simpler and more HW assisted solution would do the same job. What is needed to to in the application? A pure SW interrupt at 200kHz or toggling IOs at this frequency or PWM or else?
A timer register values snapshot, and interrupt extract code could give a clue.
If using a debugger, it is possible to put a breakpoint in the interrupt and when the program is stopped, the timer is frozen. In this case, it is possible to investigate further.
2016-12-14 12:23 PM
You only have 240 processor cycles to work with, unless you keep things very tight you are going to saturate the processor. I don't think I'd be interrupting >100 KHz. If you want to toggle pins, you can let the hardware do that.
The Cortex-M0 has very limited math support, the division and floating point stuff is all done in software, interactions with the USART will also be relatively slow. ie don't put printf() stuff, or other blocking code, in IRQHandlers or call-backs called from them.
2016-12-14 11:55 PM
Thank you for replies.
marsanne.sebastien
My main goal is toggling pins.I am trying to toggle 45 LED's and in one section only 1 led need to blink with 100 khz so i set timer for 200 kHz. When i toggle 1 led in timer callback it works ok when i said go to next LED the gpio pins toggle speed getting slower but they are using same flag so this is the problem.
And I can't understand my interrupt getting slower or the proccessor can't do that.
Turvey.Clive.002
Yes I have only 240 cycles .Buthow is this not enough.Because I only toggle pin now and it is taking 11 cycles.
And i also need to use usart and some other stuffs .if i have problem in this stage i can't do anything at the further.
I have reailized something
I am using IAR and when i use debug mode i can't set some breakpoints where i want to.
So i changed the optimization levelto NONEand now i can set where ever i want.
When i toggle pin in while loop and there is nothing except that. The frequency is 1.4 MHz
Andi change the optimization level HIGH, now the toggle speed in while loop is3.4 MHz.
I am still working on itbut i dont know is this speed change help me
2016-12-15 12:08 AM
Try using the DMA memory to gpio instead. You can trigger DMA channel 2,3,4 and 5 on TIM1 channels. So you can attach circular memory to the BSRR registers for 64 gpio's.
Or
Try using only writes to BSRR in an assembly written isr. That way you don't have to stack as much registers.
(only 2, iirc)
Also see bitbanding, so you don't have to shift.
You're looking to do things that are not compatible with arduino level software architecture.
2016-12-15 04:03 AM
Thanks you so much guys it seems working ok now.
I toggle pins with ODR->0xXXXX and it works now.
amazing
:)