[En-Nut-Discussion] AD conversion resolution?
Gerwin Voorsluijs
g.m.voorsluijs at wanadoo.nl
Wed Dec 14 18:50:37 CET 2005
Dear all,
I'm trying to use the 10bit AD conversion of the Ethernut and with some
trial and error I've managed to get some data out of it. The values I
get seem OK, but I'm a little disturbed by the fact that I don't get a
continuously climbing value out of it when I raise the voltage slowly.
For example, for the purpose I am using it (which I am sure has
continuous voltages!) I get the following set of "steps":
156 158 159 176 177 184 188 192 193 195 199 206
207 224 225 227 231 240 241 248 252 254 255 304
312 316 318 319 327 335 348 352
I know I am not using the full range of 0-5 V (I measured with a
"normal" voltmeter around 0.8-1.7 V so that seems OK)
Does anyone have any idea what is going on? Lemme include the little
piece of code I used:
#include <cfg/crt.h> /* Floating point configuration. */
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <dev/board.h>
#include <sys/timer.h>
#include <dev/adc.h>
int main(void)
{
u_long baud = 115200;
FILE *uart;
u_char ad_chk;
u_short adc_value;
NutRegisterDevice(&DEV_UART, 0, 0);
uart = fopen(DEV_UART_NAME, "r+");
_ioctl(_fileno(uart), UART_SETSPEED, &baud);
ADCInit();
ADCSetRef(AVCC);
ADCSetMode(SINGLE_CONVERSION);
ADCSetChannel(0);
for (;;)
{
ADCStartConversion();
while (ADCRead(&adc_value))
NutThreadYield();
fprintf(uart, "%i ", (int) adc_value);
}
}
More information about the En-Nut-Discussion
mailing list