Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top