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.

mov OP_2,#((sens_tm*256)/100) / 256 ;MSB sens_tm<br />

mov OP_3,#((sens_tm*256)/100) and 255 ;LSB sens_tm<br />

mov R2,hi_TH0 ;MSB hi_tmr0<br />

mov R3,hi_TL0 ;LSB hi_tmr0<br />

acall Mul_16<br />

mov hivdTH0,OP_1 ;MSB of result, which is factor 256 too hi<br />

mov hivdTL0,OP_2 ;LSB of result, so just shift byte<br />

mov wndwTH0,OP_1 ;MSB function convert uses the max. size<br />

mov wndwTL0,OP_2 ;LSB<br />

pop hi_TH0 ;calculate hi_tmr0 = hi_tmr0 - hivdtmr0<br />

pop hi_TL0<br />

clr C<br />

mov A,hi_TL0 ;hi_TL0 - hivdTL0<br />

subb A,hivdTL0<br />

mov hi_TL0,A<br />

mov A,hi_TH0 ;borrow in MSB?<br />

subb A,hivdTH0<br />

mov hi_TH0,A<br />

jnc ca_corl ;no borrow, so result still pos.<br />

mov hi_TL0,#001 ;timing is too short, so take minimum<br />

mov hi_TH0,#000 ;value, and store temp. in hi_t0<br />

ca_corl: clr C ;timing correction for lo_tmr0<br />

mov A,lo_TL0 ;lo_TL0 - proc_tm<br />

subb A,#proc_tm<br />

mov lo_TL0,A<br />

mov A,lo_TH0 ;borrow in MSB?<br />

subb A,#000<br />

mov lo_TH0,A<br />

jnc ca_crh ;no borrow, so result still pos.<br />

mov lo_TL0,#001 ;timing is too short, so take minimum<br />

mov lo_TH0,#000 ;value, and store temp. in lo_t0<br />

ca_crh: clr C ;timing correction for hi_tmr0<br />

mov A,hi_TL0 ;hi_TL0 - proc_tm<br />

subb A,#proc_tm<br />

mov hi_TL0,A<br />

mov A,hi_TH0 ;borrow in MSB?<br />

subb A,#000<br />

mov hi_TH0,A<br />

jnc ca_crhv ;no borrow, so result still pos.<br />

mov hi_TL0,#001 ;timing is too short, so take minimum<br />

mov hi_TH0,#000 ;value, and store temp. in hi_t0<br />

ca_crhv: clr C ;timing correction for hivdtmr0<br />

mov A,hivdTL0 ;hivdTL0 - proc_tm<br />

subb A,#proc_tm<br />

mov hivdTL0,A<br />

mov A,hivdTH0 ;borrow in MSB?<br />

subb A,#000<br />

mov hivdTH0,A<br />

jnc ca_conv ;no borrow, so result still pos.<br />

mov hivdTL0,#001 ;timing is too short, so take minimum<br />

mov hivdTH0,#000 ;value, and store temp. in hivdt0<br />

ca_conv: clr A ;convert timer0 clk cycles to load values.<br />

mov B,A ;So do substraction 0-lo_t0<br />

clr C ;for lo_t0<br />

subb A,lo_TL0<br />

mov lo_TL0,A<br />

mov A,B<br />

subb A,lo_TH0<br />

mov lo_TH0,A<br />

clr C ;and same for hi_t0<br />

mov A,B<br />

subb A,hi_TL0<br />

mov hi_TL0,A<br />

mov A,B<br />

subb A,hi_TH0<br />

mov hi_TH0,A<br />

clr C ;and same for hivdtmr0<br />

mov A,B<br />

subb A,hivdTL0<br />

57

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

Saved successfully!

Ooh no, something went wrong!