View previous topic :: View next topic |
Author |
Message |
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
adc on 10f222 |
Posted: Sat Aug 01, 2009 3:09 pm |
|
|
Hi guys
Could some one show me the right syntax to get the ADC working on the 10f222.
Many thanks
Pete |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 02, 2009 1:52 pm |
|
|
I don't have this PIC to test in hardware, but I think the program shown
below will work. I used the free version of PCB (vs. 4.073) that comes
with MPLAB vs. 8.33 to compile this code.
The 10F222 only has one ADC clock available, so you can't use a clock
divisor in the setup_adc() statement. Instead, just use TRUE or FALSE
to enable/disable the ADC.
Code: |
#include <10F222.H>
#fuses IOSC4,NOWDT,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2)
//=========================
void main()
{
int8 result;
setup_adc_ports(sAN0); // A/D input on pin GP0
setup_adc(TRUE);
set_adc_channel(0);
delay_us(20);
while(1)
{
result = read_adc();
printf("%U ", result);
delay_ms(500);
}
}
|
This program has serial output on pin GP2. It assumes that you have a
MAX232-type chip connected to that pin, and then to the Rx pin on the
COM1 connector on your PC (and also a ground connection). |
|
|
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
|
Posted: Wed Aug 05, 2009 12:20 pm |
|
|
I have tried to get one of these chips working with my project but can not get it to work.
Even with the old test program flash an led every 500Ms.
The code gets program into the chip but it is not working.
Thanks
Pete |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 05, 2009 12:25 pm |
|
|
Post your LED flashing program.
Post your compiler version.
Post your programmer type. |
|
|
Guest
|
|
Posted: Thu Aug 06, 2009 6:53 am |
|
|
Hi Here is my Program
Code: | #include <10f222.h>
#FUSES NOWDT, NOMCLR, NOPROTECT, NOMCPU, IOSC4
#use delay(clock=4000000)
void main()
{
while(True)
{
output_high(PIN_A0);
delay_ms(500);
output_low(PIN_A0);
delay_ms(500);
}
} |
The version of CCS is 4.084
The programmer I am using is Mikro E EasyPic 4 board but I have also tried to use ICD_U40.
Thanks
Pete |
|
|
Guest
|
|
Posted: Thu Aug 06, 2009 6:54 am |
|
|
The output is B0 and not A0
Pete |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 06, 2009 11:24 am |
|
|
That's the GP0 pin. It comes up from power-on reset configured as an
analog input. CCS does not insert start-up code to make it into a digital
pin (like they normally do for other PICs). To use it for digital i/o, you
need to add the statement shown in bold below to your program:
Quote: |
void main()
{
setup_adc_ports(NO_ANALOGS);
|
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Aug 06, 2009 3:46 pm |
|
|
just out of curiosity - why did you pick THIS part? ( and not not much higher priced 12F family ?)
quantity PRICE ?
POWER consumption ?
other ?? |
|
|
Guest
|
|
Posted: Thu Aug 06, 2009 4:34 pm |
|
|
Thanks PCM programmer.
asmboy it would do the job that I wanted it to:
1 adc
2 outputs
1 input
and space in SMD 6 pins.
All I need to do now is get the adc working.
Once again thanks for your help.
Pete |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Aug 06, 2009 8:35 pm |
|
|
Now I know -
I just never imagined a project where I would actually need so LITTLE capability in the pic & wondered what it could be - that and ONLY that.
tx |
|
|
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
|
Posted: Fri Aug 07, 2009 10:52 am |
|
|
Hi guys
i am still having problems getting the a2d working i was trying to use the code that PCM programmer provided as a start.
i am trying to look at the voltage on a battery which then makes one of the output pin go high but i can not even get the a2d to output to rs232 on my simulator which is "ISIS"
any ideas guys
many thanks
Pete |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 07, 2009 11:52 am |
|
|
I don't have ISIS so I can't help with it. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Aug 07, 2009 12:30 pm |
|
|
How I approach a new design:
1 - I build out the hardware design fully with power decoupling and never use "plug boards" - use a DIP version of the PIC - use a Max232 or HIN202/232 wired up right.
2- I don't own/ use or ever suggest using a simulator.
3- If I had your problem - I would buy a few DIP 12F683's and program THEM - there is LOTS of help for that part - I've used /em they compile just fine on the cheepie cmd line CCS compiler too.
4- Prove out some code on THAT part and when it is working sweetly
downgrade to the part you will use in production.
Thats how I would approach the situation.
my 2.4cents |
|
|
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
|
Posted: Fri Aug 07, 2009 1:56 pm |
|
|
Hi Guys
I did do some code in 12f683 chip and the adc worked but I then got the 10f222 digital side working with help from PCM programmer.
But the ADC side I still can not get to working.
I test the code in the sim and if it plays up then I try it in hardware.
Pete |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 07, 2009 2:01 pm |
|
|
Post the current code that you're using to test the ADC problem.
Make sure you post a complete, compilable program. |
|
|
|