This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

step by step tutorial for setting sampling rate



Hi,

I am trying to set the sampling rate for the ADC with inputs from three sensors. I wish to sample at a rate of 100 Hz.

I've been looking at the manual but to no avail as i am confused on how to divide 32k clock down to 100 Hz so I can use it. Do I have to use the internal divider?

or Can i just do 32k/327 = 100 Hz. Can someone please help me out. I am relatively new to this and it is difficult to learn by just looking at the manuals.

Much thanks appreciated,

Allen

  • You need to generate requested sample rate at the output of some timer that can be used as trigger input for the ADC12 in repeated scan mode.

    E.g., you may use TA0 (SHSx = 1) in toggle mode with a period halved than that requested (because of the toggle).

    To obtain exactly the desired frequency from 32786 Hz you could set DCO to 32768 * 5 * 5 = 819200 Hz, then select SMCLK as source for timer and ADC, then you should set TACCR0 to 8192/2.

    Regards,

    Peppe

  • Unfortunately, 32768Hz (from a watch crystal I assume) is not a multiple of 100Hz. So if you configure the timer to trigger a conversion every 327 crystal ticks, you'll be 0.68 ticks too early. 8and with 328 ticks 0.32 ticks too late.
    A good approximation is to use 328 for two and 327 for every third cycle. (328+328+327 = 983 crystal ticks for 0.03s, which gives 32766.66 ticks prer second). The average resulting samplign frequency would be 100.004hz.
    Just using 327 or 328 would give 100.208Hz or 99.9Hz.

**Attention** This is a public forum