Been thinking about projects and bits an pieces. With the work that hippy did with a 20x2 based timer a few years ago I thought about adapting it to a 28x2 instead. I ran into difficulties and then life took over.
However now I think I may have gotten closer to what I need, full control over the start and stop control of the timer, which can be either hardware or software, and sub millisecond timing. I hoping to be able to use this as a chronograph at some point.
Some work needed on the maths side of things, and the picaxe will be tied up while timing in this manner. hopefully I got the maths that I have done so far correct
I haven't gotten around to testing this yet, I don't know when I will. If you have the things, please feel free to do so.
However now I think I may have gotten closer to what I need, full control over the start and stop control of the timer, which can be either hardware or software, and sub millisecond timing. I hoping to be able to use this as a chronograph at some point.
Some work needed on the maths side of things, and the picaxe will be tied up while timing in this manner. hopefully I got the maths that I have done so far correct
I haven't gotten around to testing this yet, I don't know when I will. If you have the things, please feel free to do so.
Code:
#picaxe 28x2
setfreq em64
'generate PWM signal and pass through and gate to c.0
'second leg of and gate connected to b.7
'pokesfr $CD, %10000111 'poke t1con if needed to set correctly
'can poke preload values in into trm1l and tmr1h if needed
settimer count 65530
pwmout B.0, 1, 3 '8mhz pwm
do
loop while pinc.3 = 0 'start timing
high b.7 'set and gate to on
do
b0 = flags
if bit7 = 1 then
inc b1
flags = 0
end if
loop while pinc.4 = 0 'end timing
low b.7 'set and gate to off
peeksfr $ce, b2 'get tmr1 LSB
peeksfr $cf, b3 'get tmr MSB
'now, do some maths.
'with preload over flow happens 0.000625ms
'at 8mhz overflow from 0 to 65535 will be 8.191875ms
'b1*(8.191*1000) will give whole ms - overflow issues
'@ 8mhz PWM a clock signal will last 0.000000125s
'each unit in the tmr1 registers = 0.125us - 0.000125ms
'will need to find the best way to do the maths here...