9 years, 2 months ago.

Modulate ticker period

I have a fast ticker (16 us) and i want to modulate period (without detach and attach, not accurate). How can I do ?

edit :

i did it old way with registers and it works. Thank you for your help.

Question relating to:

can you post an sample piece of code of how you did it ?

posted by Raph Francois 11 Jul 2015

1 Answer

9 years, 2 months ago.

Are you just trying to generate an external signal such as a squarewave with variable period? Ticker may be too slow at that rate, but all depends on the cpu clock and your specific needs. A PWMOut may be a solution. Alternatively you may have to use a dedicated counter+interrupt, but that solution depends on the target platform that you want to use. Provide more details on what you want to achieve.

Hello, I want to do audio recording at 44100 Hz. It's 22.67 us period and I cannot do that with a good enough accuracy so my real sampling rate is 45400 Hz (3% error). It's not a problem for most applications but in my case, it's for signal processing and i need to have a sampling period error < 0.1 %). I can access that precision if i modulate timing (ex 23 us, ..., 23 us, 22 us, 23 us, ..., 23 us, 22 us), a few us jitter is not a problem on my application. My goal is just a fast change of ticker period to do that.

Actually i have a dirty solution with a 4 us period and adjustment but a 4 us ticker period consum a lot of computation time...

posted by fabien comte 18 Feb 2015

Typically the mbed Ticker runs at a resolution of 1 us. Generating any interrupts at other resolutions would need one of the available timers or counters. That means you have to do some programming yourself and it wont be portable between all mbed platforms without writing the code for all of them. Since you seem to use the F411 there may be an option to use the FastPWM lib provided here and link the PWM output pin to an input pin which will trigger your ADC. FastPWM should allow you to set the period in clockticks, which is plenty accurate at 100MHz. Obviously it could be done nicer when you use the PWM counter (or some other counter) directly, but that takes more coding and study of the manual.

posted by Wim Huiskamp 20 Feb 2015