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 CCS Technical Support

12f675 ADC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

12f675 ADC
PostPosted: Sun Mar 15, 2009 9:17 am     Reply with quote

I need to have a program to read a ADC value from AN1. The following is part of my program and it works.
Code:

#include <12f675.h>
#device adc=8

....

main()
{
   int advValue;
   setup_adc_ports(sAN1|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(1);

    .....

   delay_us(10);
   adcValue=read_adc();

}

The adcValue read is around 100 (this is correct)

I need to implement a software RS232 without MAX232 chip and added
Code:
#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A2,bits=8, INVERT, stream=RS232IN)

after #device adc = 8
When I hook up the RS232 connection, the adcValue changed to 18
It seems that it is reporting the value is not in the range VSS_VDD.
I added
Code:

   setup_comparator(NC_NC_NC_NC);
   setup_vref( FALSE );

but the result is the same.
Any idea how to correct the problem?

Rgds.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 15, 2009 1:00 pm     Reply with quote

Post a complete test program. Take the code that you posted, and
add the #fuses, #use delay(), and #use rs232() statements to it.
Add a printf statement that displays the ADC value.
Add a while(1); statement at the end of the program.

Add a few lines of code to make it into a complete test program
that is compilable.

Post your compiler version.
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

PostPosted: Sun Mar 15, 2009 6:21 pm     Reply with quote

Code:
#include <12f675.h>
#device adc=8

#FUSES NOWDT     
#FUSES INTRC_IO, PROTECT
#use delay(clock=4000000)

#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A2,bits=8, INVERT, stream=RS232IN)
#use rs2232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A5,bits=8,stream=outdata)

main()
{
   int   adcValue;

   setup_comparator(NC_NC_NC_NC);
   setup_vref( FALSE );
   setup_adc_ports(sAN1|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(1);


   while (true) {
        delay_ms(1);
        adcValue=read_adc();
        fprintf(outdata,"(%d)", adcValue );
   }
}

The reading is around 20 (not correct). After I cut the connection DB9 pin 3, the value came back to normal - 100

Complier is OCH 3.249

Rgds.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 15, 2009 10:12 pm     Reply with quote

Quote:
I need to implement a software RS232 without MAX232 chip and added
Code:
#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A2,bits=8, INVERT, stream=RS232IN)

After I cut the connection DB9 pin 3, the value came back to normal - 100.

Do you have a series resistor between pin 3 of the Com1 connector
on your PC, and pin A2 on the PIC ? You need one. Normally, a 22K
ohm resistor is used with this type of direct connection. You only need
a resistor between the Tx pin of Com1 on the PC (pin 3) and the Rx pin
on the PIC. Without that resistor, you are putting -10v at 20ma
(or more) on pin A2 of the PIC. That could be the cause of your problems.
Guest








PostPosted: Mon Mar 16, 2009 2:04 am     Reply with quote

Yes. I have a 47K resistor.

Rgds.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 16, 2009 2:14 am     Reply with quote

1. What is the Vdd voltage for your PIC ?

2. What are you using for a power supply for the 12F675 ? Is it a voltage
regulator ?

3. Do you have a pull-up resistor on the MCLR pin ? What value is it ?

4. Why do you have the PROTECT fuse enabled for this project ?
Guest








PostPosted: Mon Mar 16, 2009 7:15 am     Reply with quote

1. Vdd is +5V
2. The power is stealed from Pin 4 and Pin 7 of the RS232 by using 1N4148 diode as an input for 78L05 regulator. The output of the 78L05 regulator will power up the circuit
3. a 10K pullup for MCLR
4. PROTECT is our my standard fuse

Rgds.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 16, 2009 12:22 pm     Reply with quote

I can't find my 12F675 right now. If I find it later, I'll test your code.
When I test it, I will use a bench power supply, and not serial port power.
I also will use a Max232A chip instead of INVERT mode. And I will not
use the PROTECT fuse. If it doesn't work, I will install a 4 MHz crystal,
instead of the internal oscillator.

In other words, I will do whatever it takes to make it work, by using
standard methods, rather than trying to "push" every aspect of the
design.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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