Multiple ADC channels problem - MC9S08QE128

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multiple ADC channels problem - MC9S08QE128

1,911 Views
SamLiu
Contributor I

Hi All,

 

I am using MC9S08QE128 as a data logger, which samples a total of 9-channel signals using the ADC module. I am using timer interrupt to control the sampling rate, and ADC interrupt for sampling the data.

 

The basic idea here is that, in the timer interrupt, enable the ADC interrupt, and disable ADC sampling inside the ADC interrupt, where the ADC sampling data will be kept in a global buffer, which will be stored into SD card later on. When next timer interrupt occurs, enable the ADC again...

 

However, I have questions about how to select/switch channels before the ADC interrupt occurs. if you guys have any suggestion or comments, please do let me know.

 

Thank you very much in advance!

 

Regards,

 

Sam

Message Edited by NLFSJ on 2009-09-16 01:12 PM
Labels (1)
0 Kudos
4 Replies

327 Views
bigmac
Specialist III

Hello Sam, and welcome to the forum.

 

To select an ADC channel, and start a new conversion, the ADCSC1 register must be written, with the ADCH bits identifying the channel on which the conversion is to take place.  Any write to this register will abort the current conversion, and commence a new conversion.  Since you need to monitor nine channels, you should select single conversion mode.

 

I assume that the timer interrupt period is much greater than the ADC conversion period.  For each interrupt it is not clear whether you require to initiate a single conversion on the next channel in the cycle, or perhaps you need to sample all channels in quick succession, within the timer interrupt period.

 

In the first case, the situation is very simple - you would not need to use the ADC interrupt.  Within the timer ISR, read the result of the previous reading, increment the current channel, and initiate a new reading on the new channel.

 

For the second case, the situation is a little more complex.  Within the timer interrupt, enable the ADC interrupt, and initiate a reading on the first channel.  Then, when each ADC interrupt occurs, read the previous conversion result, increment the current channel, and initiate a new conversion.  In the event that all nine conversions have been completed, disable further ADC interrupts, rather than start a conversion.

 

Regards,

Mac

0 Kudos

327 Views
SamLiu
Contributor I

Thanks, bigmac.

 

Yes, I need to sample all channels within each timer interrupt period, which is about 33.3 ms corresponding to a sampling rate of 30Hz. 

 

I have tried what you said, however, I ran into another problem. As I mentioned before, I use a global data array as data buffer to temporarily keep the sampling data until the data buffer is full (450 data points) and it will be stored into SD card via SPI. To maintain a constant sampling rate, neither of the interrupts is stopped during the data storing process. My problem is that as long as I use this global data array in the interrupt, the program will stop running after some time. I increased the stack size up to 0x800 in case of stack overflow. However, the problem was still there. In debug mode, I noticed that the register value (TPM1SC, etc.) was changed when the program stopped unusually. 

 

Any suggestion on this?

 

Thank you very much!

 

Regards,

 

Sam

 

 

0 Kudos

327 Views
bigmac
Specialist III

Hello Sam,

 

The problem is a bit difficult to diagnose without seeing the code.  You do not mention the manner in which the "program stopped running".  Did a reset occur?  If so the cause of the reset should be evident by monitoring the SRS register.

 

Are you attempting to implement "nested" interrupts, by re-enabling interrupts whilst within an ISR?  This should be avoided.  Another possibility is a wayward pointer within your ISR code causing the hardware registers to be overwritten.

 

Regards,

Mac

 

0 Kudos

327 Views
SamLiu
Contributor I

Hi bigmac,

 

When the "program stopped running", there is no reset occuring. I have checked this by running the code while having the debugger connected, and the connection of the debugger was all right. I had a LED to indicate the sampling process, which would blink when sampling happens. When the "program stopped running",the LED stopped blinking, and by checking the hardware registers in the debug mode, the values were overwritten.

 

I keep the timer interrupt always on, since I need a constant sampling rate. 

 

I attached my code here, just not sure if you got time to take a look. I will greatly appreciate if you can help me identify the problem.

 

Note: the code attached is a previous version in which I use only timer interrupt, and ADC was performed within the ISR. The new version with ADC interrupt is a little bit messy...

 

Thank you very much in advance!

 

Regards,

Sam

 

QE128_IMS.zip

Message Edited by t.dowe on 2009-09-17 09:37 AM
0 Kudos