Re: Pulse counter/freq-volt converter
- From: "petrus bitbyter" <pieterkraltlaatditweg@xxxxxxxxxxxxxxxxx>
- Date: Fri, 2 Mar 2007 20:35:23 +0100
"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
.
- References:
- Re: Pulse counter/freq-volt converter
- From: petrus bitbyter
- Re: Pulse counter/freq-volt converter
- Prev by Date: Re: Looking for a 20 Bit DAC for Industrial Control
- Next by Date: Re: absorbing reactance into series LC
- Previous by thread: Re: Pulse counter/freq-volt converter
- Next by thread: Test
- Index(es):
Relevant Pages
|