NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Sensors, Actuators, and Robotics » Slow sample rate down (prescaler?)
|
NerdKits » Forums » Sensors, Actuators, and Robotics » Slow sample rate down (prescaler?) (15 posts)
|
|
|
May 03, 2011 by amartinez |
I am working with ADC (among other things). I'm trying to make a simple voltmeter just to try out. I am using the code for the tempsensor and utilizing the input pin 23 (PC0) as a voltage probe (0-5V) Question: I don't like the sample rate, it's way too high. How can I slow it down? The prescaler is set to 115.2Khz. I need it much lower, much much lower, possibly in the two digit hertz range meaning I need to divide 1/409600. At present it's 1/128. I need to slow the sample rate down for two reasons. 1- It will look better to me as the numbers won't cycle so fast 2- I would like to leave the MCU clock cycles free for other sensors in the future. I feel it's a waste of cycles. Am I asking too much? If not, how is this done? Do I change this line of code? If so, what needs to be changed?
Thank you Al |
|---|---|
|
May 03, 2011 by Noter |
I don't think you can go less than 50khz. Take a look at chapter 23 in the datasheet and see if you come to the same conclusion. |
|
May 03, 2011 by bretm |
Sure you can. Just don't start the next sample until you need it. |
|
May 04, 2011 by Rick_S |
To paraphrase Noter and bretm, while you can't slow the actual speed of the ADC below a certain point (Noter), you can reduce the overhead you see in the tempsensor program by only taking a sample when you need to (bretm). In other words, leave the ADC speed alone, but set the program to poll the ADC maybe once per second and then display the results. Or, take a 100 sample average once per second and display the result. If you want less frequent updates, span your sample time to every 2 or 3 seconds. Rick |
|
May 04, 2011 by Ralphxyz |
This is why I started my jumpy ADC thread. Look at bretm's pseudo code. I have not tried it yet but it looks good. Once we get this the solution should go into a FAQ don't you think? Ralph |
|
May 04, 2011 by Rick_S |
FAQ Plug |
|
May 04, 2011 by Ralphxyz |
[quote]FAQ Plug  and Noter published an over sampling code sample that should also do the trick. Ralph |
|
May 06, 2011 by amartinez |
Ralph, thank you for your help on this. Actually I got it to do exactly what I needed it to do using the delay_ms function right under the sample routine in the tempsensor code.
Am I missing something? It seems to work fine. Great thread guys. It was fun to read and really informative. |
|
May 06, 2011 by bretm |
Nope, not missing anything. That's really all you need to do unless you want to do other work during those 2 milliseconds. |
Please log in to post a reply.
|
Did you know that you can connect a computer keyboard to your microcontroller? Learn more...
|