PDA

View Full Version : lm34 and Ad590 with PIC16f877



wlp01
- 18th November 2005, 09:52
Hello, i need help with interfacing these temperature sensors with serial port of the computer through PIC16f877. This is my first time using PIC.
I have found the example of lm34 at this website http://www.rentron.com/PicBasic/LM34.htm. I have tried to do exactly like that, however the serial connection doesn't receive anything. I'm not sure whether the PIC or the crystal is still functioning properly.
I dont have the MAX233, so i chosed to do direct connection instead. The code was modified as said on that website.

DEFINE loader_used 1 ' Boot loader is being used
DEFINE debug_mode 1 ' Debug sending True serial data
DEFINE debug_reg portc ' Debug Port = PortC
DEFINE debug_bit 6 ' Debug.bit = PortC.6
DEFINE debug_baud 9600 ' Default baud rate = 9600
DEFINE osc 4 ' We're using a 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
samples VAR WORD ' Multiple A/D sample accumulator
sample VAR BYTE ' Holds number of samples to take
temp VAR BYTE ' Temperature storage
samples = 0 ' Clear samples accumulator on power-up

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
PAUSE 500 ' Wait .5 second

loop:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 0, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20
DEBUG "Temperature is: ",DEC temp," Deg F",10,13
samples = 0 ' Clear old sample accumulator
GOTO loop ' Do it forever

END

P.S i have attached a picture of how i have connected the 4MHZ crystal oscillator.

Is there anything else that im missing or what i did wrong? How should i modified the code to implement with AD590 sensor? Sorry for asking too many question.

Thank you for your help!
Peter

J_Brittian
- 18th November 2005, 21:32
Hi Peter,
Unfortunately this post doesn't have your answer, but I do have a couple of questions. How are you connected to your computer? What program are you using to receive the data? Have you set up the baud rate parameters in the program? Why are you using Debug instead of Serout?
You also mentioned that your not sure if the program is running. The best thing to do then is make the PIC perform an output just before it loops. If you have an LED and a current limiting resistor then have the pic toggle the led each loop.

wlp01
- 19th November 2005, 10:12
hey thank you for replying.

FYI, i didn't wrote that code. It came from the website. I have connected to the PC through the serial cable with pin5 of DB9 to GND, and pin 2 connect to 1koHm --> portC.6. To receive the data, i used a free PicBasic MicroCode Studio editor RS-232 terminal program, and also tested with hyper terminal at 9600baudrate-8bits-N-1. I think the function of debug and serout is the same.
About your suggestions for debugging. Do you mean to add a serout line test before looping to test the PIC? Then connect a LED to a certain output port and add "toggle LED" inside the loop to test the crystal oscillator? Im sorry man, i'm very new at this. Anyway, thank you very much.

Peter

wlp01
- 21st November 2005, 02:56
It turns out that i wasn't using the right type of cap(disk type). Now i got hyperterminal to show something(see attache image), but it's all garbage. I have tested the program at baud rate of 2400, 4800, an 9600. I have also change the font to Corrier New, no luck either. Can anyone help me with this please..

thanks, Peter