Re: Pulse counter/freq-volt converter




"petrus bitbyter" <pieterkraltlaatditweg@xxxxxxxxxxxxxxxxx> schreef in
bericht news:45e72cbf$0$3860$e4fe514c@xxxxxxxxxxxxxxxxxxxxxxxxxxx

<snip>

If I can find the time I'll write some example code tomorrow.

petrus bitbyter


Well, a full example but beware. Is has not been debugged.
Layout has been messed as the mailer replaced the tabs with one space.

#include <p12f629.inc>
list p=PIC12f629

#define pulses_in GPIO, T1CKI ; pin 2
#define startsw GPIO, GP1 ; pin 6
#define stopsw GPIO, GP2 ; pin 5
#define output GPIO, GP0 ; pin 7
#define counter1oo T1CON, 0

tmr1_on equ b'00000111'
tmr1_off equ b'00000110'
tmr0_ini equ b'00000111'
count0 equ 0x20
count1 equ 0x21
stopswcntr equ 0x22
tenscntr equ 0x23
tensecs equ .152

__CONFIG H'3FA4'
ORG 0
goto init
ORG 0004
int retfie
init
movlw 0xfe ; GP0 (pin7) is output
tris GPIO
movlw tmr1_off ; init TMR1 for use as
movwf T1CON ; an asynchronous counter
movlw tmr0_ini ; init 10s counter
bsf STATUS, RP0 ; switch to bank 1
movwf OPTION_REG
bcf STATUS, RP0 ; back to bank 0
restart
bcf output ; output = 0
bcf PIR1, TMR1IF ; reset 730 pulses counted flag
movlw (0xffff-.730)/0xff
movwf TMR1H ; re-init counter
movlw (0xffff-.730)&0xff
movlw TMR1L
clrf stopswcntr
movlw tensecs
movwf tenscntr
idle
btfsc startsw
goto idle
movlw 6 ; wait 6ms for debounce
call dx1ms
btfsc startsw
goto idle ; disturbance, ignore
bsf output ; output 1
bsf counter1oo ; start 730 counter
clrf TMR0 ; clear 10s cntr and prescaler
bcf INTCON, T0IF ; clear TMR0 roll-over flag
tensecsloop
btfsc PIR1, TMR1IF ; if 730 pulses counted
goto restart ; then start again.
btfss stopsw ; stopswitch pushed?
goto nostop ; no, continue.
decfsz stopswcntr,f ; if stop switch pushed too
goto tst10s ; short then count down
goto restart ; remaining checks else restart.
nostop
clrf stopswcntr
tst10s
btfsc INTCON, T0IF
goto tensecsloop
decfsz tenscntr,f
goto cont10cnt
goto restart
cont10cnt
bcf INTCON, T0IF
goto tensecsloop
;
; delay for w * 1ms
;
dx1ms
movwf count0
dms
call us100
decfsz count0,f
goto dms
retlw 0
us100
movlw 0x21 ; delay 100us
movwf count1
nxt6
decfsz count1,f
goto nxt6
retlw 0
END


petrus bitbyter


.



Relevant Pages

  • Re: KeyPad Lock made from a 16F84A trouble
    ... A key pad combination controlled lock. ... > STATUS equ 03h ... > movlw 01h ... > movwf NUM1 ...
    (sci.electronics.design)
  • R: Problem with LCD & PIC16C54C
    ... PORTA EQU 0x05; Physical Address on PIC ... movlw timehigh ... movwf COUNTHIGH ... SDELAY;delay ...
    (sci.electronics.design)
  • Re: PIC 18F242 PortA Problem
    ... All goes well until it get to PORTA. ... > SECONDS equ h'000' ... > movlw h'60' ... > movwf TRISA ...
    (sci.electronics.design)
  • Re: PIC 16F84A Problems
    ... > simply counts up in binary and displays the count on LEDS connected directly ... > STATUS equ 03h ... > movlw 00h ... > movwf TRISB ...
    (sci.electronics.design)
  • Re: Building from within Visual Studio IDE
    ... DDKBUILD VERSION 3.12.35 FREEWARE FROM HOLLIS TECHNOLOGY SOLUTIONS ... NEQ "-verbose" goto noverbose ... "-debug" shift ...
    (microsoft.public.development.device.drivers)