Need guidence for programming a DS1821C+


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2008
    Posts
    31

    Default Need guidence for programming a DS1821C+

    I've been away from PICs for a while but a project has me digging out my old PBP 2.5a (see other thread about Windows 7). Once I get in up and running I'll likely need a bit of help.
    I need to program a few DS1821 thermometer/thermostat to operate in thermostat mode. If I'm figuring it correctly I can use OWIN, OWOUT to program a PIC to then program the DS1821C+. I have both an EasyPIC3 dev. board (also not working yet, Windows 7 issue?) and melabs U2 programmer. I bought all this stuff years ago, including PBP but only used it for a few weeks before being pulled away. I fear I've wasted a bunch of $$ as this stuff is all too outdated.
    Anyway, am I on the right track for programming the DS1821?
    TIA
    Neo

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    http://www.picbasic.co.uk/forum/cont...r-nine-of-themhttp://www.picbasic.co.uk/forum/cont...r-nine-of-themHi neo,

    Below is a code snippet from my WIKI article on reading the DS18b20 temperature sensor...

    you may find something usefull if you go look at that article.
    NOTE: most of the code I borrowed from others and simply wrote the article for the WIKI.


    Code:
    ReadSensor:
        OWOUT DQ, 1, [$55,str id\8,$44] 'instructs sensors to match[$55] this[ID] rom code and
                                        'initiates[$44] temperature conversion on matching sensor
    CkAgn:
        OWIN DQ, 4, [busy]      ' Check for still busy converting
        IF busy = 0 THEN ckagn  ' Still busy?, then loop
        owout dq,1,[$55,str id\8,$BE]   'instructs sensors to match[$55] this[ID] and start sending back scratchpad[$BE] 
        OWIN DQ, 2, [Raw.LOWBYTE,Raw.HIGHBYTE]' Read two temperature bytes, then end communications
        return
    here is a link to the article...

    http://www.picbasic.co.uk/forum/cont...r-nine-of-them

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Heckler,
    Thanks for the quick reply. I'll have a look at that.
    Still haven't been able to get my version of PBP running yet though.
    Neo

  4. #4
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Well things are looking up! I've PBP up and running as well as my U2 programmer. Haven't made the EasyPIC3 programmer work though, USB driver issue I think, but the board is useful for running the PIC after prog in the U2. I tried working with the code mentioned above from over at rentron.com but I don't have a serial LCD so went looking again. I found this "PicBasic Experiments With The PIC16F877" over at rentron.com also which fit better with the EasyPIC3 board and it's LCD in 4-bit mode.
    I'm using a 16F88 because it's what's on hand. So I edited the code to work with just a PORTA and PORTB and the LCD of the EasyPIC3 hardwired to PORTB 4-7 etc.
    I had a few problems getting it working... funny story (well not so much)... The DS1820 has it's own home on the EasyPIC3 (EP3 for short) board, a 3-pin socket labeled DS1820 with a pull-up resistor (10k). I pulled the DS1820 out of the breadboard I stuck it into for safe keeping a couple days earlier and observing polarity plugged it into the EasyPIC3. Loaded up the code from PBP to the 16F88 and dropped it into the EP3, powered up and... LCD displays "Temp in degrees" then "0.0 degrees C". Troubleshooting commenced.
    To make a long story shorter I double checked the part number of the DS1820 thinking there may be changes that were not backward compatible to the older code. What I found was a 2N2222 in the socket where the DS1820 should have been. A quick glance at the breadboard showed another TO-92 device with a dozen other resistors, capacitors, chips etc... the DS1820. Maybe not such a great place to store it.
    Anyway, swapping in the right part didn't help. Still 0.0 degrees C. Back to the code. What I found was the setting of the ADCs to digital was required. Changing the ADCON1=7 to ANSEL = 0 got me 26.5 degrees C on the LCD. I found the ANSEL=0 in an older thread here http://www.picbasic.co.uk/forum/showthread.php?t=2996. Thanks Darrel.
    I read a bit more about setting the ADCs but don't quite understand ADCON1 vs ANSEL are they chip specific? I'm looking for someone to point me to something I can read for a better understanding.
    Neo

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Yes those register names are VERY chip specific. Although you may find similarities between chips I would always check the data sheet for the chip you are using.

    That is probably the one thing that took me a while to realize. You simply can not work with these PIC microcontrollers (or other micro's for that matter) without having the data sheet available for reference. .pdf file works great.

    Just google your PIC part number and "datasheet" and find the link to Microchips web site for the datasheet.
    Now reading the data sheet is an "aquired talent" There is a LOT of information there and you have to figure out what is importaint at the moment for what you are trying to do.

    Not sure how to tell you how to go about digesting the data sheet, other than to say KEEP AT IT. Start by finding the section on the Port Pins as there you will find all the registers that are pertinant for that given Port Pin. You will have to do quite a bit of jumping around in the document as you look at each of the various registers.

    I also try and start my projects by loading a previos file that uses the same chip I am working with at the time. That way I know it worked for that previous project and I can delete most of the code and start witht the begging register configuration section.

    Dont forget the Configuration "fuses" that are set at the time the chip is flashed. This configuration register is usually what sets the watch dog timer, brown out detect, int/ext type of oscillator, how the MCLR pin behaves (as an mclr or as an INPUT) etc., etc,

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  6. #6
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Question Re: Need guidence for programming a DS1821C+

    Thanks for the tips. I've been pouring over data sheets, web pages, and PBP manual for days getting myself up to speed as best I can. I came across some code that I don't understand because of the assembly mixed in with the PBP. Why use PBP PAUSEUS 60 to pause for 60 microseconds and then @ nop to delay for 1 microsecond? (4 MHZ OSC) Is it because of the minimum resolution at 4 MHZ with PBP (guessing)? I know why the DS1821 need the timing, just not why the assembly is mixed in with the PBP. If I'm running at 20 MHZ and the resolution is higher (.2 uSec if memory serves) then would the assembly not be needed?
    TIA

    Code:
    write0:
            Low DQ
            Pauseus 60              ' Low for > 60us for 0
            DQ_DIR = 1         ' Release data pin (set to input for high)
            Return
    
    ' Write a 1 bit to the DS1820
    write1:
            Low DQ                  ' Low for < 15us for 1
    @       nop                     ' Delay 1us at 4MHz
            DQ_DIR = 1        ' Release data pin (set to input for high)
            Pauseus 60             ' Use up rest of time slot
            Return

  7. #7
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    OK, never mind I found it. Just a little more research... I was pretty tired. Any way, in case anyone else comes across this and doesn't know, here's what I found.
    @ tells PBP that the next command is assembly, the assembly command nop (also noop) is short for No Operation. Essentially means do nothing. The PIC apparently takes 1 uSec to "Do Nothing" therefore a 1 uSec delay at 4 MHZ. Using PBP (2.5c at least) the minimum delay is 24 uSec @ 4 MHZ so the assembly "nop" is a work around for shorter time delays. Makes me wonder if...
    @ nop
    @ nop
    @ nop
    @ nop

    is a 4 uSec delay? I bet the answer to that is in the PIC's data sheet.

  8. #8
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Since it takes 4 clock cycles to complete a single operation, divide the oscillator frequency by 4 to get the number of operations the PIC can perform in a second:

    4,000,000/4 = 1,000,000 operations per second.

    Take the inverse of the number of operations per second to get the time it takes to perform a single operation:

    1/1,000,000 = 0.000001 seconds = 0.001 milliseconds = 1 microsecond.

    So yes, four NOPs will delay for 4 microseconds when operating at 4 MHz.

    At 20 MHz, each NOP will delay for 200 nanoseconds.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  9. #9
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Thanks again, I think that will come in handy when I work at regaining access to the DS1821.
    I had ordered some DS1821 and they arrived today. I wrote some code to query and write to the DS1821 setting and reading the various registers and finally put it into thermostat mode. It works. Mostly.
    The issue I'm having now is the logic hi / low levels don't seem to match the spec in the data sheet, unless I don't understand it, which is most likely.
    I'm reading that the DS1821 can sink 4mA minimum. Yet in thermostat mode with a logic 0 on the DQ pin I can drive it to a logic 1 by measuring the voltage on the DQ Pin if I reference Vdd (+5 volts). In other words Red lead on DQ (PORTA.0) Black lead on +5 volts forces a logic high and reads -3.7232 VDC (avg) which is of course inverted because of the reversed leads. My meter is a Fluke 189 with 10M ohms impedance, I figure I'm loading the circuit with +500 nano amps and forcing it to a logic 1. I tried my other Fluke meter with the same results. Tried 1 meg ohm pull up and pull down resistors but the DS1821 seems to have no drive, it can't overcome the 1 Meg Ohm resistor either high or low. Even TOUCHING the free end of a 1 meg ohm resistor plugged into the DQ line of the DS1821 forces it to a logic high.
    It does produce high and low states to PORTA.0 on the PIC as it's supposed to but I wasn't planning on using a PIC in the final circuit, I was going to drive a MOSFET with the DS1821 and wanted a pull down resistor on the gate but it seems even a 10 Meg Ohm is not an option. What's the solution with such small signals?
    Data sheet is HERE (DS1821) if anyone wants to have a look.
    TIA
    Neo

  10. #10
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Once again, problem solved. Operator error. I'll blame it on working 16 hour days and bread-boarding at 1:00 am. Lets just say the power supply was inadequate. I'm getting very good logic states now. In the future I'll try to sleep on a problem before asking about it.
    Neo

Similar Threads

  1. need help programming
    By chris000 in forum General
    Replies: 1
    Last Post: - 20th May 2009, 05:18
  2. new to PIC programming could really do with some help
    By karenhornby in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2008, 14:03
  3. I2C programming
    By goku24m in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th October 2007, 03:12
  4. gps programming
    By chuckad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th June 2006, 01:02
  5. New to PIC Programming
    By Keiou in forum General
    Replies: 3
    Last Post: - 29th October 2003, 19:13

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