12F508 and Dallas 1820 not working


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2012
    Posts
    7

    Default 12F508 and Dallas 1820 not working

    Hello

    I am old but new here, just found this forum.

    I have written several Picbasic Pro programs using 16F873 or later 16F876A, LCD-display and Dallas 1820 temperature sensors. Now I wanted to make a simple thermostat using the attached code with 12F508. I can't get it working. The program starts ok, I see the led flashing for 1 sec, but then I think the program cannot get any result from the sensor. The rom code is ok, tested the same sensor with 16f876A. I think the problem may be, that I cannot use 12F508 registers right. Here is the code and I WANT to use 12F508 if possible. Please help
    GPIO.0 is the led pin
    GPIO.1 is the data pin


    '-----------------------------------------

    led var GPIO.0

    Tempa Var Word ' Temperature storage
    Stat var bit

    DQ Var GPIO.1 ' One-wire data pin

    TRISIO =%00000010 '???? maybe wrong?
    GPIO =%00000000 '???? maybe wrong?




    'flash led to see if running

    high led
    PAUSE 1000
    low led

    'read 1820

    Temp_1:

    OWOUT DQ, 1, [$55,$10,$B2,$AD,$D8,$00,$08,$00,$26,$44]
    W1:
    OWIN DQ, 4, [Stat]' Check for still busy converting
    IF Stat = 0 THEN W1' Still busy?, then loop
    OWOUT DQ, 1,[$55,$10,$B2,$AD,$D8,$00,$08,$00,$26,$BE]
    OWIN DQ, 2, [Tempa.LOWBYTE,Tempa.HIGHBYTE]' Read two bytes, then end communications


    If Tempa >= 41 then low led ' if >= 20,5 led off
    If Tempa <= 40 then high led ' if <= 20 led on

    PAUSE 1000

    Goto Temp_1

    '-----------------------------------

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    What CONFIGs are you using?

    I don't see any oscillator setting and no mention of what osc you are using.

    Robert


    EDIT: What about this?

    Note:
    Erasing the device will also erase the preprogrammed internal calibration value for the internal oscillator. The calibration value must be read prior to erasing the part so it can be reprogrammed correctly later.

    Suggestion: Do a small test program using only the LED pin and a loop turning it on and off. Get the PIC running properly first, then add the sensor logic.

    And I just have to ask, why use what appears as an archaic PIC? You have a truckload at 1 penny per dozen sitting in the yard?
    Last edited by Demon; - 7th February 2012 at 02:07.

  3. #3
    Join Date
    Feb 2012
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Sorry, I forgot to mention, that I use internal oscillator, and I have set that when programming the chip. I use Epic to program the chip, and internal oscillator is selected there. I tested everything with simple led blink program and it worked ok. And as I mentioned, also the attached program starts fine. Led at GPIO.0 comes up for one second but the program never comes out from sensor routine (Temp_1). I have tested that by adding simple led on/off routine to before Goto Temp_1. So, my guess is, that I cannot configure the data pin (GPIO.1) right. I have used PortC.6 or PortC.0 when using 16F876A and those pins do not require any special configuration.

  4. #4
    Join Date
    Nov 2008
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    If you are using the internal osc you might want to setup the osccon register. I don't see it in your code.
    Regards
    CharlieM
    Using PBP3
    MCSPX

  5. #5
    Join Date
    Feb 2012
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Thanks.

    I do not know what OSCON has to do with this, because test program (led blink) works, so the program is running without any OSCON-setting. The orinal calibration value is there. The only problem is DS1820 sensor handling. The same read loop (Temp_1) works very well with 16F873 and 16F876A running 4 MHz. The only difference is that I use here GPIO.1 as DQ-pin instead of PortC.0 with those 16F series chips. Maybe I have to try to ask rentron.com, what is wrong with my code with 12F508.

  6. #6
    Join Date
    Nov 2008
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    I do not know what OSCON has to do with this, because test program (led blink) works, so the program is running without any OSCON-setting. The orinal calibration value is there. The only problem is DS1820 sensor handling. The same read loop (Temp_1) works very well with 16F873 and 16F876A running 4 MHz. The only difference is that I use here GPIO.1 as DQ-pin instead of PortC.0 with those 16F series chips. Maybe I have to try to ask rentron.com, what is wrong with my code with 12F508.
    I may have been wrong. It looks as though this pic does not have a osccon register. I tried your code on a 12F683 and it did not work either.
    Regards
    CharlieM
    Using PBP3
    MCSPX

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Hi,

    The first thing is to be sure of your sensor ID ...

    The second ... to be sure the bytes are transmitted in the right sequence ( not swapped )

    from this point of view ... why not try to write and read to it skipping this ID. That could point closer to the reason your code doesn't work ...


    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Feb 2012
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Thank you again.

    The sensor ID is correct. I have tested the same sensor and the same piece of code with 16F876A using PortC.0, and I can read the sensor without any trouble. Hardware is ok, checked it carefully. Again my opinion is, that something is wrong with my code with GPIO.1. I am not an engineer, and I am not sure how these pins work in 12F508. When using 16F876A or 16F873 no special configuration is needeed. Just define:

    DQ var PortC.0

    and everything works.

  9. #9
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    576


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Instead :
    TRISIO =%00000010 '???? maybe wrong?
    try :
    TRISGPIO + %00000010
    since I think don't exist TRISIO (see page 32 of datasheet : just TRISGPIO, TRISC, GPIO ....where GPIO is refferenced as PortB)

  10. #10
    Join Date
    Feb 2012
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    "Instead :
    TRISIO =%00000010 '???? maybe wrong?
    try :
    TRISGPIO + %00000010"

    --> Syntax error

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Are you really sure of your OWIN parameters ???

    I'm not !!!

    Alain
    Last edited by Acetronics2; - 10th February 2012 at 16:23.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    576


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Sorry... TRISGPIO = %00000010

  13. #13
    Join Date
    Feb 2012
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Quote Originally Posted by Acetronics View Post
    Are you really sure of your OWIN parameters ???

    I'm not !!!

    Alain
    Thank you. I am fairly new with Picbasic, but all that code is directly copied from rentron.com Picbasic sample page. Only changed the DS1820 ID. I again double checked the ID and the code. I have a check board with a suitable program and an LCD. I just plug in any DS18x20 and can I see immediately the ID and CRC-code. By the way, my english may not be good. I am from Finland.


    See the original code at Rentron:

    http://www.rentron.com/PicBasic/one-wire2.htm

    and find Temp_1 label.

    The code works exteremely well with my other programs with 16F87xx Pics. I also changed my sample code a bit and used GPIO.2 as data pin. Datasheet says "General Purpose IO-pin", just like PortC-pins on 16F87xx. But this tiny chip is against me. I have also tested another 12F508 without success. Maybe I have to give up

  14. #14
    Join Date
    Feb 2012
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 12F508 and Dallas 1820 not working

    Oh sh*t!!!

    I had forgotten to connect a pull-up resistor to data pin, and that was the reason for non workin code. I am sorry, that I have caused trouble. The following works. Data pin is now back to GP1 (GPIO.1)



    Code:
    '****************************************************************
    '*  Name    : 12F508thermostat.BAS                                          *
    '*  Author  : AN OLD FINNISHMAN                    *
    '*  Notice  :                                    *
    '*            :                                 *
    '*  Date    : 02/12/2012                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                    *
    '*          :                                                   *
    '****************************************************************
    
    ' CHIP: PIC 12F508
    ' A simple program to read DS1820 (18S20) and depending on the temperature
    ' to drive a led (and/or a solit state relay to drive an 
    ' electric heater).
    ' ID for the sensor and a CRC value is here:
    ' $10,$B2,$AD,$D8,$00,$08,$00,$26
    ' replace it with yours
    ' USE INTERNAL OSCILLATOR (INTRC) 
    
    ' connect a led via 470 ohm resistor to GP0
    ' connect a 4k7 pull-up resistor to data pin GP1
    
    
    Define osc 4
    
    led var GPIO.0
    
    
    Tempa Var Word            ' Temperature storage
    Stat var bit
    
    DQ    Var    GPIO.1            ' One-wire data pin
    
    TRISIO =000010
    GPIO =000000
    
    'led on for a second to see if code runnig
    
            High led 
            PAUSE 1000
            low led
    
    pauseus 100
    
    Temp_1:
        
        OWOUT DQ, 1, [$55,$10,$B2,$AD,$D8,$00,$08,$00,$26,$44]
    W1:
        OWIN DQ, 4, [Stat]' Check for still busy converting
        IF Stat = 0 THEN W1' Still busy?, then loop
        OWOUT DQ, 1,[$55,$10,$B2,$AD,$D8,$00,$08,$00,$26,$BE]
        OWIN DQ, 2, [Tempa.LOWbyte,Tempa.HIGHBYTE]' Read two bytes, then end communications
        
    ' replace upper and lower limits with your own
    ' variable Tempa is 2 times the temperature in degrees C
        
    If Tempa >= 41 then low led ' if temp >= 20,5 (upper limit)
    If Tempa <= 40 then High led ' if temp <= 20 (lower limit)
    
    PAUSE 1000
    
    Goto Temp_1
    Last edited by Picprogman; - 10th February 2012 at 18:18.

Members who have read this thread : 1

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

Posting Permissions

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