hallo
I'm trying to measure a pulselength. On int0 and 1 i connecting a square wave of 20 to 200Hz.
I expect a stable reading, but this is completly precarious.
Must i use "no save" on INT0 and 1?
Can i do a "atomic reading" of TCNT1?
[code:1:841cd969f3]
'Int0 & Int1 : together: PD2 - PD3
'
$regfile = "m16def.dat"
$crystal = 16000000
$hwstack = 32
$swstack = 8
$framesize = 32
$baud = 38400
'Config Portb.4 = Output 'for test
On Int0 Int0_isr
On Int1 Int1_isr
Config Int0 = Rising 'start TIMER1
Config Int1 = Falling 'stop TIMER1
Enable Int0
Enable Int1
Config Timer1 = Timer , Prescale = 1
On Timer1 Timer1_isr
Enable Timer1
Enable Interrupts
Dim Ovf_1 As Byte
Dim I As Word
Dim N As Long
Ovf_1 = 1
Do
Print N
Enable Interrupts
Loop
End
'-------------------
Timer1_isr:
Incr Ovf_1
Return
'------------------
Int0_isr:
'Set Portb.4 'test
Enable Timer1
Return
'------------------
Int1_isr:
'Reset Portb.4 'test
Disable Timer1
Disable Interrupts
I = Tcnt1h
I = I * 256
I = I + Tcnt1l
N = Ovf_1 * 65536
N = N + I
Ovf_1 = 0
Return
'-------------------
[/code:1:841cd969f3]
[b:841cd969f3][color=red:841cd969f3](BASCOM-AVR version : 2.0.7.6 )[/b:841cd969f3][/color:841cd969f3]
↧