CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

adc on 10f222
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pdl



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

adc on 10f222
PostPosted: Sat Aug 01, 2009 3:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Aug 02, 2009 1:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Aug 05, 2009 12:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Aug 05, 2009 12:25 pm     Reply with quote

Post your LED flashing program.

Post your compiler version.

Post your programmer type.
Guest








PostPosted: Thu Aug 06, 2009 6:53 am     Reply with quote

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








PostPosted: Thu Aug 06, 2009 6:54 am     Reply with quote

The output is B0 and not A0

Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 06, 2009 11:24 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Aug 06, 2009 3:46 pm     Reply with quote

just out of curiosity - why did you pick THIS part? ( and not not much higher priced 12F family ?)
quantity PRICE ?
POWER consumption ?
other ??
Guest








PostPosted: Thu Aug 06, 2009 4:34 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Aug 06, 2009 8:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 07, 2009 10:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 07, 2009 11:52 am     Reply with quote

I don't have ISIS so I can't help with it.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Aug 07, 2009 12:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 07, 2009 1:56 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 07, 2009 2:01 pm     Reply with quote

Post the current code that you're using to test the ADC problem.
Make sure you post a complete, compilable program.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group