View previous topic :: View next topic |
Author |
Message |
Guest
|
10f222 ADC |
Posted: Thu Sep 24, 2009 8:18 am |
|
|
Hi Guys
Has anyone got the ADC working on a 10f222 ? If so has anyone got any example code that I can look at ?
Pete |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 24, 2009 6:19 pm |
|
|
Here is demo program for the ADC on the 10F222. This was tested in
hardware with vs. 4.073.
A 10K trimpot was connected between +5v and ground. The wiper of
the trimpot was connected to the AN0 pin (GP0) on the 10F222. Pin GP2
was connected to the Rx pin (pin 2 on a DB9) on the COM1 port on the
PC. Pin 5 on the DB9 was connected to ground on the 10F222 board.
There is a 10K pull-up resistor on the MCLR pin.
While running the program, the trimpot was turned from one limit to
the other limit. The follow output was displayed in a terminal window
on the PC. This is correct output.
Quote: |
0
0
19
58
88
117
128
154
191
232
255
255
255
|
Here is the demo program:
Code: |
#include <10F222.H>
#fuses IOSC4,NOWDT,MCLR
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, INVERT)
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
//=========================
void main()
{
int8 result;
set_options(0xDF); // Enable pin B2 for normal i/o
setup_adc_ports(sAN0);
setup_adc(TRUE);
set_adc_channel(0);
delay_us(20);
while(1)
{
result = read_adc();
printf("%U \n\r", result);
delay_ms(500);
}
}
|
|
|
|
eabir
Joined: 16 Aug 2010 Posts: 19
|
|
Posted: Fri Oct 28, 2011 4:08 am |
|
|
ok,
but my question was what is the best way in coding in order to follow the count increament. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|