HC908GP32 - How to use the ATD at 20KHz

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

HC908GP32 - How to use the ATD at 20KHz

1,710 Views
kelvinNgai
Contributor I

Hi all,
Anyone can teach me how to use the ATD at 20KHz sampling rate.
void ATDInit(void) {
//UINT8 atdc;
//10 bits unsigned no prescler
ATD1C = 0x80; // /* ATD1 Control Register; 0x00000050 */
ATD1SC = 0x60; // /* ATD1 Status and Control Register; 0x00000051 */
ATD1PE = 0x01;
}

i use the internal clock only which should be 4Mhz. I know the conversion frequency is 0.5MHz - 2MHz right?
So in order to achieve 20KHz, what can do, use a timer??

thank you very much!

--
Alban Edit: FSL Part Number in Subject line + split/moved to appropriate location.

Message Edited by Alban on 2007-03-23 09:56 PM

Labels (1)
0 Kudos
Reply
3 Replies

575 Views
rocco
Senior Contributor II
Hi, Kelvin:

Yes, use a timer.

You do not mention which microcontroller you are using, so I will describe what I did on the HC908GP32 when I needed 5 kHz sample rate.

The GP32's ADC performs a conversion in about 17 microseconds, which was too fast. Rather than use the ADC interrupt, I programed the Time-Base Module (TBM) to give me an interrupt every 200 microseconds, and used that interrupt to read the conversion results from the ADC and to fire-off the next conversion. It gave me a precise 5 kHz sampling frequency, with only a few microseconds of inter-sample jitter, due to interrupt latency.

If your microcontroller has an RTI or TBM module, maybe you can program it for 50 microseconds. If not, you could certainly program a timer to interrupt every 50 microseconds.
0 Kudos
Reply

575 Views
bigmac
Specialist III
Hello Kelvin,
 
I assume you only need to convert a single channel.  If more than one channel, the method proposed by Rocco will become a little more complex - and two channels is probably the upper limit for 50 microseconds sampling interval per channel.
 
For a single channel, a slight variation on Rocco's method could be to set the ADC for continuous conversion, and simply interrogate the last completed reading each 50 microseconds, as determined by a timer interrupt.
 
It is important that the timer interrupt processing be as short as possible - you certainly cannot afford to start a conversion, and  then wait until it completes, whilst remainining in the ISR.
 
Regards,
Mac
 
0 Kudos
Reply

575 Views
rocco
Senior Contributor II

bigmac wrote:

. . . It is important that the timer interrupt processing be as short as possible . . .
Yes. Especially at 20 kHz.

In my routine, I assumed the conversion was complete (it better be, after 200 microseconds), so I didn't even check the ADC flags. All that I needed to do in the ISR was:

1) Clear the timer interrupt,
2) Read the converted value from the ADC and stuff it in a buffer, and
3) Start the next conversion.

Altogether, the ISR takes under 5 microseconds. If I were sampling at 20 kHz, I would have already used 10% of my cpu bandwidth, without having processed anything yet.
0 Kudos
Reply