11 years ago.

Measuring a 50Hz sine wave using a ticker?

1 Answer

11 years ago.

I answered this question yesterday:

This code is wrong:

for(int i=0;i<128;i++)
{
   printf("%f\n\r", samples[ADC_Count]);
}

You need to use the correct index or all you see is the value stored in samples[ADC_Count].

for(int i=0;i<128;i++)
{
   printf("%f\n\r", samples[i]);
}

There is also the issue that your ticker continues to run and so the sampling continues and the array index ADC_Count exceeds the valid range of the array...

Please use the <<code>> tag before your code and close the code section with <</code>> at the end. These tags should be on separate lines.

Sorry I'm quite new to programming how do I stop the Ticker after 128 samples are taken?

Thanks

posted by Alan Carson 11 Nov 2013

Check the Ticker page in the handbook: http://mbed.org/handbook/Ticker

You can disable the ticker by calling:

ADC_set.detach();

Do this right after the while loop where you wait for the 128 samples to complete. There is still some probablity of overrun due to delays. Have a go and try to solve that problem.

posted by Wim Huiskamp 11 Nov 2013

Thanks very much Wim much appreciated

posted by Alan Carson 11 Nov 2013