05.09.2013 Views

2.3 Relaxatie-oscillator

2.3 Relaxatie-oscillator

2.3 Relaxatie-oscillator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

fr_6: jb sensor,fr_6 ;loop during sensor is hi<br />

mov R3,#num_per ;temporarily counter for number of captures<br />

mov OP_0,#000 ;not used<br />

mov OP_1,#000 ;possible carry from TH1 (updated in TIMER1)<br />

setb EX0 ;enable EX0 (but not yet EA)<br />

setb ET1 ;enable interrupt from timer1 overflow<br />

fr_strt: jnb sensor,fr_strt ;loop during sensor is lo<br />

fr_h2l: jb sensor,fr_h2l ;loop during sensor is hi<br />

setb TR1 ;timer1 runs: start with measuring<br />

clr IE0 ;no hardware to reset, so software does this task now<br />

setb EA ;enable interrupts (vectored to EXT0)<br />

fr_loop: cjne R3,#000,fr_loop ;wait for num_rep captured timingdata<br />

;R3 is decreased through int. routine EXTI0<br />

clr EA ;finished measuring, disable all interrupts<br />

clr TR1 ;stop timer1<br />

clr EX0 ;disable _INT0<br />

clr ET1 ;disable interrupt from timer1<br />

mov OP_2,TH1 ;timer1 MSB result in OP_2<br />

mov OP_3,TL1 ;timer1 LSB result in OP_3<br />

mov R2,#000 ;MSB of divider<br />

mov R3,#num_per ;LSB of divider<br />

acall Div_16 ;calc.: OP_(0..3) \ num_per = <br />

mov prd_h,OP_2 ;store result counting in prd<br />

mov prd_l,OP_3 ;store result counting in prd<br />

mov C,wvmem ;put port sensctrl through carry in original state<br />

mov sensctrl,C<br />

setb EA ;enable interrupts<br />

ret ;ready with measuring & calculating<br />

;*******************************************************************************<br />

;* wavectrl -> wvmem,vldsns *<br />

;* interrupt from timer0 occurred, so there’s some work to do. Precalculated *<br />

;* values for TH0 & TL0 determine how long the hi-state (in hi_TH0 & hi_TL0) *<br />

;* for vldsns=0 and (hivdTH0 & hivdTL0) for vldsns=1 lasts, followed by how *<br />

;* long lo-state (in lo_TH0 & lo_TL0) on output port sensctrl will last. *<br />

;*

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!