Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

using 32768 crystal (12F629, 12F683)

Status
Not open for further replies.
I seem to recall running into the impedance of an AVR or PIC I/O pin impedance figure a ways back; might have been for the ADC though. In the range of 40-60kohms.

Certainly not for a PIC, like I say there's no set impedance, but the A2D pins have a maximum recommended source impedance of about 2K on most PIC's. This isn't due to the load impedance of the input, but due to the capacitor charging time in the sample and hold.
 
Just a note to your push button project, if you debounce in hardware (using a carefully chosen capacitor and a resistor as a low pass) you can run the switch directly to an I/O pin set to wake up the UC without having to pole so frequently.

Why do you think you would need debounce hardware? You can use a push button press to wake up the device and debounce it in software.

Mike
 
Why do you think you would need debounce hardware? You can use a push button press to wake up the device and debounce it in software.

Mike

I'm using a 12F509 as on-off control for a circuit board. The MCU is normally asleep, awakens only to change states, then goes back to sleep until the next button press.

IIRC, prelim tests indicated the chip uses 5 uA except during state change.
 
The question was meant for Sceadwian.

I don't see why he (or anyone) would want to add switch debounce hardware when you can do it in software, unless perhaps he doesn't know how?

Mike

Code:
;
;  single switch example
;
;  a switch is debounced for both "press" and "release" states by
;  sampling it at the same state 24 times within a 23 msec period
;
suspend
        movf    GPIO,W          ; clear any IOC mismatch condition
        bcf     INTCON,RBIF     ; clear IOC interrupt flag bit
        sleep                   ; sleep, wait for IOC interrupt
        nop                     ;
dbounce
        movlw   d'24'           ;
        movwf   dbctr           ; set debounce counter to 24 msecs
dbdelay
        DelayCy(1*msecs)        ; sample at 1 msec intervals
        comf    GPIO,W          ; get fresh active low switch data
        andlw   1<<SW0          ; mask off unused bits
        xorwf   slatch,W        ; changes (press or release)
        bz      dbounce         ; branch if inactive or bouncing, else
        decfsz  dbctr,F         ; debounced? yes, skip, else
        goto    dbdelay         ; test it again
        xorwf   slatch,F        ; update switch state latch
        andwf   slatch,W        ; is it a "new press"?
        bz      suspend         ; no, branch (a "new release"), else
;
;  a "new press", your "on switch press" code goes here
;
        nop                     ;
        nop                     ;
;
;  then debounce the release part of the switch cycle and sleep
;
        goto    dbounce         ;
And here is the DelayCy() sub-system for those who don't have it. Set the clock equate to your clock frequency (4, 8, 12, 16, or 20) to produce exact delays.
Code:
        radix   dec

clock   equ     8               ; user clock frequency in MHz
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier

DelayCy macro   pDelay          ; cycles (Tcy), minimum 16
        movlw   high((pDelay-16)/4)+1
        movwf   TMRH
        movlw   low ((pDelay-16)/4)
        call    DelayLo-(pDelay%4)
        endm
;                                                                 *
;  Delay(16..262159 Tcy) subroutine   Mike McLaren, K8LH, Jun'07  *
;                                                                 *
;  12 words, 1 RAM variable, 14-bit core                          *
;                                                                 *
Delay.16
        nop                     ; entry point for delay%4 == 3    |B0
        nop                     ; entry point for delay%4 == 2    |B0
        nop                     ; entry point for delay%4 == 1    |B0
DelayLo addlw   -1              ; subtract 4 cycle loop time      |B0
        skpnc                   ; borrow?  yes, skip, else        |B0
        goto    DelayLo         ; do another loop                 |B0
        nop                     ;                                 |B0
DelayHi addlw   -1              ; subtract 4 cycle loop time      |B0
        decfsz  TMRH,F          ; done?  yes, skip, else          |B0
        goto    DelayLo         ; do another loop                 |B0
        goto    $+1             ; burn off 2 cycles               |B0
        return                  ;
 
Last edited:
My thought was just for a wake from sleep button on a battery powered device as a hardware debounce to keep casual button presses from waking the MCU up at all, which depending on button placement/sensitivity could save a lot of power from incidental button pushes, a well chosen debounce resistor/capacitor will waste no power passively and trivial power actively if low loss components are used, but while the MCU is running it's debounce routine it's drawing it's full running load, it does add up. For user interface applications sure software debounce is easy, I was speaking strictly of interrupt applications where low power is key.

Also Nigel it is specified though indirectly as leakage current, I was more than a little bit off =) according to microchips website the leakage current on one of the 18F line chip's basic I/O line is 1ua, at 5 volts that's equivalent to 5meg I must have been thinking of pull-up resistor values. I don't know about other PIC lines but it is going to be high. Mind you be very careful about using pullups, as I think they're active in sleep mode so you could drain a lot more power than you want if you don't really go over your sleep mode prep carefully.
 
Last edited:
Thanks for all the great suggestions!

I often wondered about so many "gadgets" that have a push-on push-off switch that clearly is not an "alternate action switch" (which I had to figure out) and even in looking they are often say a conductive "elastomer" being pushed into a grid of printed connections - so sure enough, these little "blinky" gizmos, and other things, are RUNNING or somehow started by a button push, and have battery life in the years when not operating!

Well, back to cleaning up my office, as that's between me and some serious hardware hacking!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top