Extremely long delay loop on PIC16F84

From: CFF (cffung_at_myrealbox.com)
Date: 11/06/04


Date: 6 Nov 2004 09:04:23 -0800

I am working on my first project using a 4MHz PIC16F84. The whole
purpose of the project is to set portb<0> pin from HIGH to LOW for a
prolong period (as much as 30 minutes) before tuning back to HIGH upon
detection of activity at porta pins.

My idea is to cascade a series of fully loaded counters (I am using 4
8-bit file registers, i.e. count1 to count4, in my experiment) so as
to generate the required lengthy delay. The idea is simple but it
doesn't work out as expected however.

What's strange about the counting process is count3 will only count
from 0xFF to 0xF5 before reseting itself to 0xFF. That is where my
trouble is about. It has been confirmed both on simulator and my
hardware circuit. If I load the counters with smaller initial values,
say 0x0F, the problem disappears. Of course, smaller values doesn't
generate long delay. Can somebody give me some idea about why the PIC
behaves differently from what the programme logic states?

Below is the problematic code that I've been experimenting. Thanks for
any help.

;;;;;;;;;;;;;;;;;;;;;;;;;; PROBLEMATIC PIC CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                list p=16F84
                radix hex
                
porta equ 0x05
portb equ 0x06
count1 equ 0x0c
count2 equ 0x0d
count3 equ 0x0e
count4 equ 0x0f

                org 0x000 ; processor reset vector
                goto start
                        
start movlw 0xff
        tris porta ; configure porta as input port
                
        movlw 0x00
        tris portb ; configure portb as output port
        clrf portb ; set portb LOW
                
scan btfss porta, 0
        call timer
        btfss porta, 2
        call timer
        btfss porta, 3
        call timer
        goto scan

timer bsf portb, 0 ; set portb<0> HIGH

        ; initialise count1 to count4
        movlw 0xff
        movwf count1
        movlw 0xff
        movwf count2
        movlw 0xff
        movwf count3
        movlw 0xff
        movwf count4
                                
delay decfsz count1, f
        goto delay
        movlw 0xff
        movwf count1
                
        decfsz count2, f
        goto delay
        movlw 0xff
        movwf count2
                
        decfsz count3, f ; THIS GUY NEVER COME TO ZERO BUT 0xF5, WHY???
        goto delay
        movlw 0xff
        movwf count3
                
        decfsz count4, f
        goto delay
                
        bcf portb, 0 ; set portb<0> LOW
        return

        end



Relevant Pages

  • Extremely long delay loop on PIC16F84
    ... I am working on my first project using a 4MHz PIC16F84. ... purpose of the project is to set portbpin from HIGH to LOW for a ... to generate the required lengthy delay. ... say 0x0F, the problem disappears. ...
    (sci.electronics.design)
  • Re: Videos on Green Arrays web site
    ... The problem is a simple waveform on a port pin at a known rate. ... then one node both toggling a pin and the delay is easy and it takes ... or set the boot address for that node ... set the type of connection for the ide ...
    (comp.lang.forth)
  • Re: run a counter without a clock
    ... It was for a CPLD on a small plug-in board, ... no other need for a clock on the board. ... one pin, through a 1.5 K Ohm resistor, and into another pin. ... Adjust the resistor value to get the desired time delay. ...
    (comp.arch.fpga)
  • Re: Do you bother with reading from the LCD (HD44780)?
    ... works - but I could use that pin to control the line. ... Text output is usually so slow the extra delay does not ... you will be more limited in baudrate if you use a fixed delay. ... When I did it I had a separate task for the user interface and the ...
    (sci.electronics.design)
  • Re: run a counter without a clock
    ... It was for a CPLD on a small plug-in board, ... one pin, through a 1.5 K Ohm resistor, and into another pin. ... Adjust the resistor value to get the desired time delay. ... So either I implement a free running counter with this delay to generate an internal clock and then do all the things I need, or I simply try to count on the internal routing delay, which is quite ok on post-layout sim, but still have to try it on the hardware! ...
    (comp.arch.fpga)