View previous topic :: View next topic |
Author |
Message |
balaji
Joined: 30 Mar 2010 Posts: 21
|
PIC16F690 |
Posted: Wed Mar 02, 2011 4:22 am |
|
|
Hai all,
I`m using PIC16F690 which has been interfaced with LM35 Temperature sensor. the MCU works fine when connect my VDD to 5 volts, it means i`m getting ADC counts correctly but when i reduce the VDD to 3.3 V my ADC goes to saturation(1023 counts). I`m using internal clk @8 MHz and VRef for ADC is internal.
regards
balaji |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Mar 02, 2011 6:32 am |
|
|
There shouldn't be any reason for it not to work, but , please post a small complete program,with fuses,includes,version that shows the problem. |
|
|
balaji
Joined: 30 Mar 2010 Posts: 21
|
here is code |
Posted: Wed Mar 02, 2011 7:08 am |
|
|
Code: |
#include<16f690.h>
#DEVICE ADC=10
#use delay(internal=8Mhz)
#use rs232(baud = 9600,xmit = PIN_B7, rcv = PIN_B5,parity = n )
#fuses HS,NOWDT,PUT,NOPROTECT,NOBROWNOUT
#byte TRISA=0x85
#byte TRISB=0x86
#byte TRISC=0x87
unsigned long avg;
unsigned long value;
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
setup_adc_ports( ALL_ANALOG );
setup_adc(adc_clock_internal);
unsigned long i,avg, sum = 0;
while(1)
{
set_adc_channel(0); // Smoke detector
delay_ms(100);
value=read_adc();
printf("\n\n\n smoke count: %lu",value);
set_adc_channel(1);
delay_ms(100);
value=read_adc();
printf("\n\n\n TC: %lu",value);// LM35 input
delay_ms(2000);
output_toggle(pin_B6);// To check MCU live
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Mar 02, 2011 7:24 am |
|
|
Do not use the following !
setup_adc(adc_clock_internal);
According to the datasheet, it can only be used in sleep mode...
4: When the device frequency is greater than 1 MHz, the FRC clock source is only recommended if the
conversion will be performed during Sleep.
The two options are..
Fosc/16 and Fosc/32
according to the datasheet, table 9.1 , in the ADC section.
Also, you do not need to delay_ms(100) for the readings.
delay_us(10) ; should be more than adequate. |
|
|
ALPL
Joined: 29 Mar 2009 Posts: 30
|
|
Posted: Wed Mar 02, 2011 10:42 am |
|
|
Hello, also check the LM35 data sheet. The LM35 operates from 4 to 30V. 3.3V might not be enough. |
|
|
|