+ Reply to Thread
Results 1 to 13 of 13

Thread: pic16f628a & DS1820 @ 48kHz , 3.3V

  1. #1
    mabauti Newbie
    Join Date
    Jun 2006
    Posts
    124

    Default pic16f628a & DS1820 @ 48kHz , 3.3V

    Hi everybody:

    I'm having troubles trying to communicate a f628a and a DS1820 using the internal pic oscillator @ 48kHz, 3.3V. Communication between them @ 4MHz is successful , but @ 48kHz is not.

    My question is : is this possible (communication @ 48kHz)?, or am I doing something wrong?

    this is the modificated part (taken from the very usual code)

    Code:
            ;******************************************************************
    ;*                                                                *
    ;*  Dallas/Maxim DS18B20 Temperature Sensor Routines              *
    ;*                                                                *
    ;******************************************************************
    
    OW_HIZ:MACRO
            bsf     STATUS,RP0      ; bank 1                          
            bsf     TRISA,DQ       ; set DQ pin as HiZ input         
            bcf     STATUS,RP0      ; bank 0                          
            ENDM                    ;                                 
    
    OW_LO:MACRO 
          bcf    STATUS,RP0  ; Select Bank 0 of data memory 
          bcf    PORTA,  DQ  ; Clear the DQ bit 
          bsf    STATUS,RP0  ; Select Bank 1 of data memory 
          bcf    TRISA, DQ  ; Make DQ pin an output  
          bcf    STATUS,RP0  ; Select Bank 0 of data memory 
         ENDM 
                      ;                                 
    
    WAIT:MACRO   TIME            ;                                 
            movlw   (TIME/5)-1      ; 1 µsec
            call    WAIT5U          ; 2 µsec                          
            ENDM
    
    WAIT5U  nop                     ; 1 µsec 
           addlw -1                ; 1 µsec                                            
            bnz  WAIT5U             ; 3µsec or 2µsec             
            return                  ; 2 µsec                          
    
    OW_RESET
            OW_HIZ                                                   
            clrf    PDByte                                           
            OW_LO                                                   
            ;WAIT    .500                                             
            nop
            nop
            nop
            nop
            nop
            nop
            OW_HIZ                  ;                                 
            ;WAIT    .70             ;                                 
            nop
            btfss   PORTA,DQ         ;                                 
            incf    PDByte,F        ;                                 
            ;WAIT    .430            ;                                 
            nop
            nop
            nop
            nop
            nop
            return                  ;                                 
    ;
    ;  RX byte
    ;
    DSRXBYTE
            movlw   .8              ;                                 
            movwf   Count           ; set bit counter                 
    DSRXLP  
            OW_LO                   ; bring DQ low for 6 usecs        
            nop                                                      
            ;nop                                                     
            ;nop                                                      
            ;nop                                                     
            ;nop                                                      
            ;nop                                                     
            OW_HIZ                  ; change to HiZ and wait 4 usecs  
            nop                                                    
            ;nop                                                     
            ;nop                                                     
            ;nop                                                     
            movf    PORTA,W          ; read DQ                         
            andlw   1<<DQ           ; mask off the DQ bit             
            addlw   .255            ; C=1 if DQ=1: C=0 if DQ=0        
            rrf     IOByte,F        ; Shift C into IOBYTE             
            ;WAIT    .50             ; Wait 50µs to end of time slot   
            nop
            decfsz  Count,F         ; Decrement the bit counter       
            goto    DSRXLP          ;                                 
            movf    IOByte,W        ;                                 
            return                  ;                                 
    ;
    ;  TX byte
    ;
    DSTXBYTE
            movwf   IOByte          ; we send it from IOBYTE          
            movlw   .8              ;                                 
            movwf   Count           ; set bit counter                 
    DSTXLP  OW_LO                   ; drive the line low for 3us      
            nop                                                     
            ;nop                                                      
            ;nop                                                     
            rrf     IOByte,F                                         
            bsf     STATUS,RP0      ; bank 1                          
            btfsc   STATUS,C        ; test LSB of IOBYTE for 1 or 0   
            bsf     PORTA,DQ       ; HiZ the line if bit is 1        
            bcf     STATUS,RP0      ; bank 0                          
            ;WAIT    .60             ; continue driving line for 60µs  
            nop
            OW_HIZ                  ; release the line for pullup     
            nop                                                      
            ;nop                     ; recovery time of 2µs            
            decfsz  Count,F         ; decrement the bit counter       
            goto    DSTXLP                                           
            return                  ;                                 
    
    ;******************************************************************
    ;
    ;  get temperature reading
    ;
    GetTemp
            call    OW_RESET        ; send reset signal               
            btfss   PDByte,0        ; DS18B20 found?                  
            return                  ; no, return, else                
            movlw   h'CC'                                           
            call    DSTXBYTE        ; send 'skip rom' command         
            movlw   h'44'                                            
            call    DSTXBYTE        ; start temperature conversion    
    ReadSlot
            ;WAIT    .60             ; wait 60-usecs                   
            nop
            OW_LO                   ; start new read slot             
            OW_HIZ                                                   
            nop                     
            ;nop                     
            ;nop                     
            ;nop                     
            ;nop
            btfss   PORTA,DQ        ; conversion complete '1'?        
            goto    ReadSlot        ; no, do another slot, else       
            ;WAIT    .60             ; finish read slot period         
            nop
    GetResult
            call    OW_RESET        ; send reset signal               
            movlw   h'CC'                                            
            call    DSTXBYTE        ; send 'skip rom' command         
            movlw   h'BE'                                            
            call    DSTXBYTE        ; send 'read scratchpad' command  
            call    DSRXBYTE                                         
            movwf   TempL           ; save temperature lo             
            call    DSRXBYTE
    
                                             
            movwf   TempH           ; save temperature hi
            bcf   STATUS,C        
            rrf     TempL,f            ; eliminate "decimal" place
            return
    

    Thanks in advace for your comments


  2. #2
    Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent
    Join Date
    Jan 2005
    Location
    Michigan, USA
    Posts
    2,522

    Default

    I'm not sure you could implement the correct one-wire timing sequences for reading and writing bits with a Tcy (cycle time) of 20.8 usecs when using a 48 KHz clock...
    Last edited by Mike, K8LH; 14th February 2009 at 08:54 PM.

  3. #3
    nickelflippr Good nickelflippr Good nickelflippr Good nickelflippr Good
    Join Date
    Oct 2006
    Location
    Oregon, USA
    Posts
    488

    Default

    Like Mike says it just not possible, because you need 1us resolution. If you were into experimentation, a 10us time cycle might work? That would require a 400kHZ clock, really don't see much gain there, must be a battery operation.

  4. #4
    mabauti Newbie
    Join Date
    Jun 2006
    Posts
    124

    Default

    If you were into experimentation, a 10us time cycle might work
    I'll continue experimenting

    must be a battery operation
    Yep, that's my intention


  5. #5
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,711
    Blog Entries
    5

    Default

    The 18f doesent have a 48kHz internal osc.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  6. #6
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,817

    Default

    I think what Bill meant to say was that the 16f628a does not have a 48kHz internal clock. It is always 4MHz.

    Mike.

  7. #7
    Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent
    Join Date
    Jan 2005
    Location
    Michigan, USA
    Posts
    2,522

    Default

    There's an OSCF bit in the PCON register that selects the 4 MHz or the 48 KHz INTOSC frequency...

    Perhaps you could switch to 4 MHz to communicate with the DS18B20 devices then switch back to 48 KHz...
    Last edited by Mike, K8LH; 15th February 2009 at 12:45 AM.

  8. #8
    nickelflippr Good nickelflippr Good nickelflippr Good nickelflippr Good
    Join Date
    Oct 2006
    Location
    Oregon, USA
    Posts
    488

    Default

    That 48khz internal osc has got to take the cake, never noticed that before.

    If the O.P. is serious about saving power then put the PIC to sleep while it waits for 1-wire temp to calculate a new value.

    That looks like a bare glass LCD, how are you driving that with a 16f628a?

  9. #9
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,711
    Blog Entries
    5

    Default

    The 16F628A has a 48kHz or 4MHz internal OSC the 18F1320 does not.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  10. #10
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,817

    Default

    Quote Originally Posted by nickelflippr View Post
    That 48khz internal osc has got to take the cake, never noticed that before.
    Snap, I hadn't realised it had the two speeds.

    Mike.

  11. #11
    mabauti Newbie
    Join Date
    Jun 2006
    Posts
    124

    Default

    Perhaps you could switch to 4 MHz to communicate with the DS18B20 devices then switch back to 48 KHz...
    I want to avoid that =[ . Actually I tried , but it didn't work;

    That looks like a bare glass LCD, how are you driving that with a 16f628a?
    using an icm7211

  12. #12
    nickelflippr Good nickelflippr Good nickelflippr Good nickelflippr Good
    Join Date
    Oct 2006
    Location
    Oregon, USA
    Posts
    488

    Default

    Quote:
    Perhaps you could switch to 4 MHz to communicate with the DS18B20 devices then switch back to 48 KHz...
    I want to avoid that =[ . Actually I tried , but it didn't work;
    Have you tried putting the PIC to sleep?
    1) Assign the Timer0 prescaler to the watchdog (OPTION_REG,PSA) and Initialize watchdog timer prescale bits (OPTION_REG, PS bits). Then set the (WDTCON,WDTPS bits) for approx 100ms.
    2) After issuing a convert T command you have 100ms
    before you get the 9bit reading back so:
    3) Set WDTCON,SWDTEN bit on
    4) sleep
    5) nop
    6) Set WDTCON, SWDTEN off
    7) check your conversion bit, etc.

  13. #13
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,711
    Blog Entries
    5

    Default

    Why not use synchronous serial? The USART supports a synchronous mode and it works in sleep with any FOSC on either PIC.
    Too bad the 18F1320 doesn't have a MSSP like the 16F628A does or I'd suggest I2C or SPI
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

+ Reply to Thread

Similar Threads

  1. DS18B20 instead DS1820 - Help with code
    By fratello in forum Micro Controllers
    Replies: 18
    Latest: 16th January 2009, 02:15 PM
  2. Unicorn + Swordfish + DS1820
    By Pommie in forum Micro Controllers
    Replies: 10
    Latest: 27th February 2008, 10:34 PM
  3. DS1820 Temp.sensor
    By alpish in forum Micro Controllers
    Replies: 4
    Latest: 27th October 2007, 06:47 PM
  4. ds1820 code for 8051?
    By garg29 in forum 8051/8951
    Replies: 1
    Latest: 9th March 2005, 11:57 AM
  5. DS1820 and DS18S20
    By electricano in forum General Electronics Chat
    Replies: 1
    Latest: 12th December 2003, 07:58 AM

Tags for this Thread