0

I am currently working an atmel micro controller, the EVK1104s, which house the UC32 Data Sheet. We have actually planted this chip on a custom PCB and are inthe process of writting more firmware.

Currently, I need to tell the ADC on the Micro Controller Unit(MCU) to sample at (8k samples / second). In reality this is for sampling a microphone. Either way, the documentation is quite unclear and I was looking for some clarification.

I know that to change the sampling rate i need to change what is called the Mode Register, the register used to configure the ADC for use (pg 799 in the link above). This is the register which allows me to change the sample/hold time/ start up time, and the ADCclock.

EX(from pg 799): 
Sample & Hold Time = (SHTIM+3) / ADCClock
ADCClock = CLK_ADC / ( (PRESCAL+1) * 2 )

From what I gather, i will only need to change the PRESCAL to make the ADCClock operate at 8Khz. The problem is that PRESCAL is limited to 8 bits of resolution.

For example, if the controller is set at 12Mhz/x = 8Khz then x would need to be 1500. Because x is limited to 8 bits as i said before this would appear to be impossible, because the max is 255.

I feel that I am doing something wrong here, or not understanding what the datasheet wants me to. Can anyone confirm what I have just talked about or help direct me?

Recurrsion
  • 231
  • 3
  • 13

1 Answers1

2

You are confused about the sampling rate and the ADC rate.

The registers you refer to in the manual only control the taking of one sample. The registers allow you to control how long to sample the voltage for. This may make a difference to you depending on the circuitry involved. That is, you don't want to take the sample too fast for your circuit. (I didn't look closely at the datasheet, but some microcontrollers take several samples and average them. This behaviour is controlled by registers, too.)

But the 8 kHz sampling rate refers to how often you want to sample. That is, this is the frequency you want to trigger the individual samples. The registers you mention don't address this. You need to use a clock and an interrupt handler to move the data out of the register into storage somewhere or do something with it, and then trigger the next sample. There is also an interrupt handler that can deal with the sample as soon as it is ready. In that scheme, you use to handlers: one to trigger the samples; another to deal with the samples when they are ready.

Edit:

To explain more why you don't want such a slow ADC rate, consider how the ADC generates its data. It samples for the first bit, waits a cycle, samples for the second bit, and so on for 10 cycles. The accuracy of the result depends on the signal staying stable over all these samples. If the signal is changing, then the bits of this number are meaningless. You need to set the prescalar and ADC clock fast enough so the signal does not change, but slow enough for the signal to settle.

So yes, you want to use a clock and interrupt handler to read the data then trigger the next reading. The ADC runs independently of the processor, and will be ready by the time the interrupt runs again. (The first reading will be garbage, but you can set a flag or something to guard against that.)

volatile int running = false

Handler()
    if(running) do something with data
    running = true
    trigger ADC
    output compare += 1/8000 s
UncleO
  • 8,299
  • 21
  • 29
  • Ok, i understand what you mean about the sample & hold time. My other question right now is what i would have to change the PRESCALE register value to, to set the ADCClock to the necessary 8KHz assuming the CPU is running at 12MHz. I am not sure how an 8 bit number would allow me to get the ADCClock to the 8KHz. Do you see what i mean? – Recurrsion Apr 08 '13 at 20:20
  • @Recurrsion What I am saying is that you definitely don't want the ADC clock to be 8kHz. That is the rate at which you want to trigger the samples. You want to run the ADC clock as fast as you can and still get reliable samples. The signal is changing. Ideally, you want an instantaneous value, but the ADC can't do that, so get as close as you can. For a non-changing signal (not what you have) a slower ADC clock would give better accuracy, but that doesn't apply in your case. (If you truly want to do some filtering down to 8kHz, then take many samples and average them over each interval.) – UncleO Apr 08 '13 at 20:33
  • Ok i see what you mean, thank you for the response. If i gather correctly, I will have to set an interrupt every 1/8000seconds on the adc to write its value to some memory? – Recurrsion Apr 08 '13 at 20:40