![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hey all, i'm trying to interface the Dallas DS18S20 with a PIC 16F628 and having some problems. I can't even get the PIC to detect the presense pulse generated by the sensor. Here's my code, i've got the data line of the sensor on bit 0 on porta. Macros Code: TEMP_OUTPUT macro BANK1 ;Change to BANK1 bcf TRISA,0 ;Set PORTA,0 to an output BANK0 ;Back to BANK0 bcf PORTA,0 ;Set output pin LOW endm TEMP_INPUT macro BANK1 ;To BANK1 again bsf TRISA,0 ;Set PORTA,0 to an input BANK0 ;Back to BANK0 endm Code: OW_INIT TEMP_OUTPUT DELAY_MICRO 250 DELAY_MICRO 250 TEMP_INPUT DELAY_MICRO 60 btfsc PORTA,0 call NO_OW_DETECT TEMP_OUTPUT return Hopefully someone with some experience with these can help me out. | |
| |
| | (permalink) |
| Making 1-wire devices work is very difficult if you are doing it for the first time. I have a very bad experience with them. It takes a lot of trial and error cycles to write your own routines to communicate with them because timings are very critical over here. Make sure that your delay 250uS routines are much accurate. Also count the over-head that it takes in calling a delay routine and suctract it from the delay count because all timings are in micro-seconds so over-head makes a lot of difference. In 8051 calling a subroutine takes 24uS@12MHz and if you don't consider that it doesn't work. This page could be of help to you http://www.rentron.com/PicBasic/one-wire2.htm
__________________ "There is no way to peace, peace is the way!" | |
| |
| | (permalink) |
| Thanks for the reply. Do you think i'm waiting too long and missing the pulse then? I learnt the delay routines i'm using here from veys.com, he explains them very well and they have worked great for me in the past. Did you get yours going in the end? It says in the datasheet to hold the output pin low for 480uS minimum, but i'm holding for 500uS so that shouldn't be a problem. Then it says the sensor waits 15-60uS before pulling the line low after detecting the rising edge, so i've waited 60 there. Only other thing it says is to keep the master rx for 480uS minimum, which I haven't done because I didn't think it would matter, i've just switched it right back to an output after checking the pin to see if it's clear. Will have a look at that link and another play. | |
| |
| | (permalink) |
| Yes I got my setup running when I counted the over-head delay and subtracted it from delay count. My delay routine rounds off to 488uS for first step & 72uS for the second step. My routine goes like this DQ = 0 delay 480 ; ~488uS DQ = 1 delay 60 ; ~72uS present = DQ delay 400 ; ~424uS Stop Present variable = 0 if DS1820 is present.
__________________ "There is no way to peace, peace is the way!" | |
| |
| | (permalink) |
| Present variable = 1? Shouldn't that be 0 because the DS is pulling low? Or have we just found the reason why mine isn't working :lol: Thanks again for the reply. | |
| |
| | (permalink) |
| Oh sorry! That should be 0.
__________________ "There is no way to peace, peace is the way!" | |
| |
| | (permalink) |
| Damn, thought i'd found something then. Oh well, time to check all my timings again then, it must be those that are at fault. I have checked them with ISIS simulating my code, and I graphed the output and it all seems ok, if only there was a 1-wire library for it.
__________________ LCDGallery | |
| |
| | (permalink) |
| Hi, you can try the ff. code which was adapted from the 1-wire routines I have successfully used. Code: OW_INIT: TEMP_OUTPUT DELAY_MICRO 250 DELAY_MICRO 250 DELAY_MICRO 250 CLRWDT TEMP_INPUT WAIT4HI: btfss PORTA,0 goto WAIT4HI WAIT4LO: btfsc PORTA,0 goto WAIT4LO TEMP_OUTPUT return
__________________ "Having to do with Motion Control" | |
| |