+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    172

    Default 12f638 simple temperature monitor

    Hi all, I'm probably overlooking something simple I missed but I just can't seem to figure it out. I was messing around with a DS18B20 and a 12f683 and copied some simple code to read the DS and display the temperature from it on an LCD screen. So far so good all of that works. I tried to add what I thought was going to be a simpe IF statement to check the temperature and turn an LED on but this is turning out to be difficult for me. What is happening is the temp displays just fine on the LCD but my LED never comes on or at best it blinks on ever so slightly. I've tried a bunch of different combinations hooking the LED up so that low LED will turn it on instead of high LED and different combinations of using a pull up or down depending on what high or low I was trying but nothing seems to work. Below is the program I am using. I am used the U2 programmer from MELABS. If anyone could shed some light on this I would appreciate it. Just to make sure I am using the correct low/high syntax I have my code toggling the LED before I get into the main loop and the LED in fact works like a charm it just breaks when I get into mainloop.
    Thanks
    David

    Include "modedefs.bas" ' Mode definitions for Serout

    LCD Var GPIO.1 ' LCD TX pin
    DQ VAR GPIO.4 'pin 3 One-wire Data-Pin "DQ"
    C VAR BYTE 'Status of I/O port bit
    R_Temp VAR WORD 'RAW Temperature readings
    C_neg VAR BIT '=1 if cold bit for C set
    NEGPOS VAR BYTE 'Sign char "-" or "+"
    C_Temp VAR WORD 'Celsius Temperature
    F_Temp VAR WORD 'Fahrenheit Temperature
    maxT var word
    LED CON 2 ' pin 5 for led indicator

    ANSEL = 0 ' Set all digital
    CMCON0 = 7 ' Analog comparators off
    Pause 500 ' Wait .5 second for LCD to init
    low led
    pause 1000
    high led
    pause 1000
    mainloop:
    gosub start_Convert
    goto mainloop
    Start_Convert:
    OWOUT DQ, 1, [$CC,$44] 'Send calculate temperature command
    REPEAT
    PAUSEUS 25 'Waiting loop until reading complete
    OWIN DQ, 4, [C] 'Monitor for pin high transition ...
    UNTIL C <> 0 ' ... reading complete
    OWOUT DQ, 1, [$CC, $BE] 'Send read scratchpad command
    OWIN DQ, 2, [R_Temp.LowByte,R_Temp.HighByte] 'get temperature
    IF R_Temp.11 = 1 THEN 'check below zero bit
    C_neg=1
    NEGPOS = "-"
    R_Temp = ~R_Temp + 1
    ELSE
    NEGPOS = "+"
    C_neg=0
    ENDIF
    C_Temp = R_Temp >> 3 'Get whole # of degrees & first decimal bit
    'SEROUT LCD , n2400,[$fe, 1,"C = ",NEGPOS,#C_Temp/2," deg. C",10,13]
    F_Temp = C_Temp * 9
    F_Temp = F_Temp / 5
    F_Temp=F_Temp/2 'remove decimal bit
    IF NEGPOS="+" THEN
    F_Temp = F_Temp + 32
    ENDIF
    IF NEGPOS ="-" AND C_Temp <= 36 THEN 'was 18 - caused error!
    F_Temp = 32 - F_Temp
    NEGPOS = "+"
    ENDIF
    IF NEGPOS="-" AND C_Temp > 36 THEN 'was 18 - caused error!
    F_Temp = F_Temp - 32
    ENDIF
    SEROUT LCD , n2400,[$fe, 1,"F = ",NEGPOS,#F_Temp," deg.F",10,13]
    C_Temp = C_Temp/2
    if F_temp =>70 then
    low LED
    else
    high LED
    endif
    return
    end

  2. #2
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: 12f638 simple temperature monitor

    Just a couple of ideas.

    1. You have no pause in your main loop so you are polling the DS18B20 extremely fast. You may want to try a Pause 1000 (1second) in between you gosub start_Convert and your goto mainloop.

    2. Your If/Then LED logic in start_Convert will only light the LED when the temperature is below 70 degF.
    Code:
    if F_temp =>70 then
    low LED
    else
    high LED
    endif
    Regards,
    TABSoft

  3. #3
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    172

    Default Re: 12f638 simple temperature monitor

    Tabsoft, Thanks...... I tried the pause but doesn't seem to have any effect. I have my LED reversed at the moment so low LED should actually turn it on when it gets above 70. Just for giggles I moved the LED up to GPIO.0 and it works perfectly. I think I am not initializing GPIO.2 correctly.... When I did have the LED blinking very dimly the blink seemed to corresponded to when the LCD was getting data sent to it on GPIO.1... it seemed to blink the same time the LCD would flash when updating. Perhaps I can't use GPIO.2 for an output to light the LED.


    Quote Originally Posted by Tabsoft View Post
    Just a couple of ideas.

    1. You have no pause in your main loop so you are polling the DS18B20 extremely fast. You may want to try a Pause 1000 (1second) in between you gosub start_Convert and your goto mainloop.

    2. Your If/Then LED logic in start_Convert will only light the LED when the temperature is below 70 degF.
    Code:
    if F_temp =>70 then
    low LED
    else
    high LED
    endif

  4. #4
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    442

    Default Re: 12f638 simple temperature monitor

    Davy,

    Our dearly departed Darrell Taylor (world class programmer, *(my opinion)) left us with this little tidbit...
    it's an include file that will set most any PIC's pins to "all digital"
    just put this file in the same directory as your code and then put this line somewhere near the top of your code

    Code:
    INCLUDE ALLDIGITAL15.BAS
    you may need to eliminate other attempts to turn off analog's so they don't confilict.

    Note: the 15 in the file name indicates that it is his version 1.5

    I hope this helps and that I haven't led you astray as I am not the greatest programmer
    Attached Files Attached Files
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  5. #5
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: 12f638 simple temperature monitor

    Try these settings:

    OPTION_REG = $FF
    INTCON = $00
    PIE1 = $00
    PCON = $10
    ANSEL = $00
    CMCON0 = $07
    TRISIO =$00
    WPU = $00
    IOC = $00
    CCP1CON = $00
    ADCON0 = $00

    Change this "LED CON 2 ' pin 5 for led indicator" to this
    "LED var GPIO.2"
    Regards,
    TABSoft

  6. #6
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305

    Default Re: 12f638 simple temperature monitor

    Perhaps I can't use GPIO.2 for an output to light the LED.
    You can use GPIO.2 to light an LED if properly designed. I don't know much but I know that. Since you moved it to GPIO.0 and it worked then it should be designed correctly.

    I think tabsoft has it right to change LED to LED var GPIO.2

    Ifn that doesn't work can you show schematic?

  7. #7
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: 12f638 simple temperature monitor

    Just curious if you got this issue resolved David.
    Regards,
    TABSoft

Similar Threads

  1. cheap and simple way to measure temperature
    By Heckler in forum Schematics
    Replies: 14
    Last Post: - 7th March 2011, 22:56
  2. AC main monitor
    By tallen in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 25th August 2009, 16:23
  3. voltage monitor
    By aftab in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 17th August 2007, 09:57
  4. Baby Monitor
    By inoonan in forum Serial
    Replies: 2
    Last Post: - 14th September 2006, 22:54
  5. Car monitor
    By Christopher4187 in forum General
    Replies: 2
    Last Post: - 27th March 2006, 18:13

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts