cancel
Showing results for 
Search instead for 
Did you mean: 

Maximum timer frequency

milan
Associate II
Posted on February 15, 2011 at 15:00

Maximum timer frequency

9 REPLIES 9
milan
Associate II
Posted on May 17, 2011 at 14:25

I forget to write that i'm trying to do a software sigma-delta modulator. the code in the main loop is reading from SD card pcm values and therefore i need the interrupt vector. I don't know how to setup it..

For a s/d modulator there are only few instructions i know the limitations for isr

Posted on May 17, 2011 at 14:25

Why does it have to interrupt?

If you want it to toggle an output, just program the timer to do that, and let it run. No interrupts required. Frequencies in the MHz are quite possible, pretty sure I could easily demonstrate 8 or 9 MHz. You could do higher frequencies, but there are likely more appropriate ways to do so, 18 or 36 MHz might also be viable, but I think that is stupidly high and a poor use of a timer.

The problem with interrupting is that your servicing code will run continuously. At 2.5 MHz and a CPU @ 72 MHz you have around 29 cycles to do all your work. Running in FLASH can cost upto 3 cycles per read (worst case, non-sequential accesses). You'd want to do it in assembler, and not be calling library routines, and be in-lining constants.

I don't think you can do much viable work in 10-30 cycles, such tasks would be better solved with hardware.

So think about your problem, and find a more viable solution.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 14:25

 

I forget to write that i'm trying to do a software sigma-delta modulator. the code in the main loop is reading from SD card pcm values and therefore i need the interrupt vector. I don't know how to setup it..

 

For a s/d modulator there are only few instructions i know the limitations for isr

Consider using the Timer's PWM functionality, you can control the frequency and pulse width.

Consider the period over which you want a specific frequency output, presumably longer than a single cycle.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
milan
Associate II
Posted on May 17, 2011 at 14:25

Yes, i have done the PWM output but i will compare the ''quality'' with s/d. therefore i need to setup the timer corectly. The frequency which i need for timer interrupt is exact 2,048MHz, but i don't know how to set it up

thanks for reply

Posted on May 17, 2011 at 14:25

Yes, i have done the PWM output but i will compare the ''quality'' with s/d. therefore i need to setup the timer corectly. The frequency which i need for timer interrupt is exact 2,048MHz, but i don't know how to set it up

 

72 MHz is not cleanly divisible by 2.048 MHz, you'd probably need to use a 8.192 MHz external crystal/source, and run the STM32 at 65.536 MHz (69.632 MHz, or 73.728 MHz probably exceeds to specs, but might work)

Assuming that 73.728 MHz is viable.

  /* Time base configuration */

  TIM_TimeBaseStructure.TIM_Period = (36 - 1); // 1-65536

  TIM_TimeBaseStructure.TIM_Prescaler = (1 - 1); // 1-65536, Master Clock Divisor

  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // 1,2 or 4 for tDTS

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

One then will have to look at how fast GPIO's can actually be made to toggle, reading/writing to the APB is probably not as fast/efficient as you might think.

SysTick is also another method to get rapid interrupts, but again you'll need to look at the prescaler and divisor/counter granularity.

The performance will be a total dog, and you really need to be running all your code from RAM. There are surely more cost effective ways to do this than to saturate an STM32.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
milan
Associate II
Posted on May 17, 2011 at 14:25

Yes you're right i tried it with this configuration

    TIM_TimeBaseStructure.TIM_Period = 35; // 1-65536

    TIM_TimeBaseStructure.TIM_Prescaler = 0; // 1-65536, Master Clock Divisor

    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

which is not exact 2.048MHz on my configuration(~2.057MHz), but maximum frequency which i got (on PB7) was ''only'' ~800kHz. ABP1 is clocked @ 36MHz and i really don't know if it's enought for read/write operations.You know? I thought about the SysTick, but didn't tried. Maybe you're right with effectivity of this sollution, but i will try it.

Thank you for your answer

Posted on May 17, 2011 at 14:25

The output frequency is going to be half the interrupt frequency.

Instead of toggling an IO, try incrementing a RAM variable printing the count once per second, and coding the interrupt service routine in assembler.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 14:25

A VL Discovery  running at 24 MHz in FLASH

SysTick saturated at around 750000 interrupts/second (32 cycles)

TIM3 saturated at around 500000 interrupts/second (48 cycles)

A reworked TIM3 saturated at around 630000 interrupts/second (38 cycles)

Not sure it's worth much more experimentation.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
milan
Associate II
Posted on May 17, 2011 at 14:25

When it's not possible to do the GPIO toggling then it does't have any price for my. Thank you for the measuring and explanation the problem. today i will try it but i give only small chances