??? 01/26/05 16:53 Read: times |
#85834 - help with duty cycle measurement |
Hello i am using a temp sensor smt160 http://smartec.nl/temperature_sensor.htm which gives temp in terms of duty cycle.I am using the 8052 to measure the duty cycle.For a certain period of time i am measuring the high period as well as the total period.I using timer0 as a timer with gate enabled to measure the high period while timer1 is used as measure the whole period.I am using the method 1 described in this pdf.
http://www.8052.com/users/gop8051/appsmt01.pdf But still i am getting bizzare results with huge swings in the timing.i am not able to make out what i am doing wrong.I have checked sensor with oscilloscope and is alright.i did a small test how many interrupts it will give in certain period and result is matching with the datasheet. /*This routines makes measurement for a certain period of time Msr_dutycyc: push ACC call TI0_init call TI1_init setb P3.7 ;Startup the temp Sensor jb P3.2,$ jnb P3.2,$ ;Waiting for sensor startup setb EA jnb Int2,$ ;Waiting for the first 1-0 interrupt to start measurement clr EA chk_pin: jnb P3.2,$ ;Wait here till timer overflows which is jb TF1,Ovr_flw ;preloaded to overflow after certain period of time jb P3.2,$ ;and all the periods within this period are measured jnb P3.2,chk_pin Ovr_flw: setb EA jb Int2,$ clr EA call Addoffset clr P3.7 pop ACC ret ;*********Timer0 and Int0 Intialisation*************** ;Timer0 in 16 bit timer mode an di initialise external interrupt TI0_init: anl TMOD,#0F0h orl TMOD,#009h mov TL0,#000h mov TH0,#000h setb IT0 clr IE0 clr TR0 clr TF0 setb EX0 ret ;**********Timer1 intialisation************************** ;Timer1 in 16 bit timer mode TI1_init: anl TMOD,#00Fh orl TMOD,#010h mov TL1,#LOW(0FFFFh-OFFSET) mov TH1,#HIGH(0FFFFh-OFFSET) clr TR1 clr TF1 ret ;Interrupt which handles the 1-0 transitions Interrupt0: push ACC jnb Int2,FrstInt clr TR1 clr TR0 mov T0L,TL0 mov T0H,TH0 mov T1L,TL1 mov T1H,TH1 clr TF1 clr Int2 pop ACC ret ;********When measuring the first routine*********** FrstInt: setb TR1 setb TR0 setb Int2 pop ACC ret AddOffset: push ACC push PSW clr C mov a,T1L add a,#LOW(OFFSET) ; this offset is set to so that mov T1L,a ;timer1 overflows after some time mov a,T1H ; to count a certain no of periods addc a,#HIGH(OFFSET) mov T1H,a pop PSW pop ACC ret |