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

A/D converter from 16F876

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Francesc
Guest







A/D converter from 16F876
PostPosted: Tue Dec 30, 2003 8:03 am     Reply with quote

Question Hi all, we would use the A/D converter on pin RA5 and use an external voltage reference on pin RA3 from 16F876.
I write thats lines, but that not work with our 2,5V external reference connected on pin RA3.

What configuration we need ??

Also, when include the line SETUP_ADC_PORTS(A_ANALOG_RA3_REF), the LCD not show nothing.

#include <16f876.h>
#device ADC=10
#USE DELAY(CLOCK=4000000,RESTART_WDT)
#include <LCD2.C>
#USE FAST_IO(A)
#USE FAST_IO(B)

LONG TEMP=0;

VOID MAIN()
{
SETUP_ADC(ADC_CLOCK_DIV_8);
SETUP_ADC_PORTS(A_ANALOG_RA3_REF);//If include that line, LCD not show nothing.
LCD_INIT();

lcd_gotoxy(1,1);
LCD_PUTC("TEST:");

while(1)
{
RESTART_WDT();
set_tris_a(0x28); ////RA3 / RA5 inputs

SET_ADC_CHANNEL(4);
TEMP=READ_ADC();
delay_ms(200);
display(); //Show results

}
}

Please, Help

Merry Christmas for all
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 30, 2003 3:09 pm     Reply with quote

My suggestions are:

1. First, make it work with the internal Vref. (ie., VDD).
Don't attempt to use the external Vref until later.
So use this line for the A/D setup:
SETUP_ADC_PORTS(ALL_ANALOG);

2. Get rid of the WatchDog Timer, during initial testing.
Use NOWDT in your #fuses statement.

Once you have it working, then you can put these other
features back in, one at a time.

Questions:

1. You said that if you put in this line, the LCD shows "nothing".
SETUP_ADC_PORTS(A_ANALOG_RA3_REF);

What do you mean by "nothing" ? Do you mean that it shows
a value of 0000 ? Or, do you mean the LCD is blank ?

2. What pins on the PIC are used by the LCD ? Does it use
any pins on Port A ?
Francesc
Guest







A/D converter from 16F876
PostPosted: Wed Dec 31, 2003 12:55 am     Reply with quote

Hi all,
When we include that line SETUP_ADC_PORTS(A_ANALOG_RA3_REF) on my program the LCD display is blank, not show nothing.
Also, not work with external reference,but it work with internal reference.
The pins used for LCD are all PORT B and bits 1,2,3 of PORT A.
That are the code

Please Help me!!!

#include <16f876.h>
#device ADC=10
#USE DELAY(CLOCK=4000000)
#include <LCD2.C>
#USE FAST_IO(A)
#USE FAST_IO(B)
LONG TEMP=0;
VOID MAIN()
{
SETUP_ADC(ADC_CLOCK_DIV_8);
SETUP_ADC_PORTS(A_ANALOG_RA3_REF);//If include that line, LCD not show nothing.
LCD_INIT();
lcd_gotoxy(1,1);
LCD_PUTC("TEST:");
while(1)
{
RESTART_WDT();
set_tris_a(0x28); ////RA3 / RA5 inputs
SET_ADC_CHANNEL(4);
TEMP=READ_ADC();
delay_ms(200);
display(); //Show results
}
}

Merry Christmas
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 31, 2003 1:41 am     Reply with quote

Quote:
The pins used for LCD are all PORT B and bits 1,2,3 of PORT A.

The use of some pins on Port A for the LCD is the problem.

With this line, you are setting up Port A to have all analog pins,
except for RA3, which is for Vref:
SETUP_ADC_PORTS(A_ANALOG_RA3_REF);

The LCD requires Digital pins for the control signals E, RS, and R/W.
Because you have those 3 pins configured as Analog pins, the
LCD will not work.

But, Port A can't be configured in the mode that you need.
Look at the following chart in section 11.0 of the 16F876 data sheet:
PCFG3:PCFG0: A/D Port Configuration Control bits
Pick the best possible configuration from that chart.
You will need to move your LCD control signals to some other pins.

When you have picked the best configuration, then look in the 16F877.H
file to find the #define value that CCS uses as a name for that
configuration. Then change the parameter in setup_adc_ports()
to use that new value.
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