Affordable and flexible platform to ease prototyping using a STM32F103RBT6 microcontroller.

Nucleo F103RB - unable to sample over 10kS/s

15 Apr 2017

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?

30 May 2017

Hello Wojciech,

The modification to the Ticker interface posted here might help.

You need to log in to post a reply