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.
9 years, 3 months ago.
Read adc via Irq
I am trying to read 10 analogs via a timer. The data is stored in an array:
static uint16_t Set0IGA[5][60][10];
To initialize the timer I have DoAdc.attach(&ReadAnalogs, 0.1); DoAdc is defined as Ticker DoAdc;
All it must do is to fill an array of 5 minutes of data. Unfortunately it crashes at random spots.
Any idea how to debug this in mbed.?
The irq routine is:
// Read analogs by IRQ every 100mS void ReadAnalogs() { // toggle Led 1/2 sec if ( LedGI++ < 4) { LedOnGI = 0; } else if (LedGI < 9 ) { LedOnGI=1; } else LedGI = 0; myled = LedOnGI; SolSet0IGA[Tm][Ts]Tmm] = Adc1.read_u16(); / // toggle to next arrays spot if( TmmI++ >= 9) { Tmm = 0; // if 1 sec done inc sec count if( Ts++ >= 59) { Ts= 0; // Reset to 0 seconds if ( Tm++ >= 4) { // Minutes = 5 Tm = 0; // if done 1 week then reset to 0 } } } }
1 Answer
9 years, 3 months ago.
What is the main code doing in the background while the timer is filling the array? Does it read the ADC at any point? If have seen crashes caused by the main loop being in the middle of an ADC read when an interrupt triggers another ADC read.
I'm assuming that Tm,Ts and Tmm are all globals and initalised to 0 in the main code. Any chance that they are getting changed elsewhere?
Hi Andy Thanks for the response. Yes Tm,Ts,Tmm are globals. Yes it is reading adc also. Stupid me let me sort that MANY thanks I will revert again
posted by 12 Aug 2015
Please use
posted by Andy A 12 Aug 2015<<code>> and <</code>>
to make format the code correctly.