Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hello!
I am working on a testing device for power grids. In my application I need to sample a signal with frequency 10240Hz. I wanted to use a Ticker object and perform sampling in an interrupt, but I have a problem - when Ticker period is less than 100us (and I need 98us) an interrupt does not execute.
Here is my sample code:
#include "mbed.h" #define N 2048 AnalogIn ADC(PA_0); Ticker ticker; volatile uint16_t DataADC[N]; volatile int Counter = 0; void Sampling(void) { if(Counter < N) { DataADC[Counter] = ADC.read_u16(); Counter++; } } int main(void) { ticker.attach_us(&Sampling, 98); while(1) { if (Counter == N) { ticker.detach(); for(Counter=0; Counter<N; Counter++) { printf("%d \n", DataADC[Counter]); } } } }When Ticker period is greater or equal to 100 everything works fine. When I go below 100 program freezes and no interrupt is executed. Function ticker.attach() gives the same result.
Do you have any ideas why it happens? Or how can I sample signal with given frequency in other way?