I have used a 12F675 to create a simple square wave with a duty cycle of 75% - 80% (not crucial) with a variable period which can have a number of possible values ranging from 0.714128 secs to 2.666667 secs. The circuit works as expected but seems to have a problem of accuracy and stability.
The application requires accuracy of better than 0.01% and I would like it to be better than 10 us.
Initially I used the internal timer, not expecting great results. In fact the output (read on a picoscope) was pretty stable down to 0.1%. Then I used an external 8 MHz crystal with inbuilt capacitor which gave slightly worse results. The period fluctuated by 2 or 3 ms.
In both cases the period was about 4 -5 ms lower than the program should have created, which is at least 50x acceptable error.
I have removed some of the code for clarity but the basis of the program is as follows:
DEFINE OSC 8 'Using an 8 MHz resonator
ANSEL=0 'Set to digital operation
TRISIO=%00001011 'Set GP0,1 & 3 to input GP2 to output rest dont care
OPTION_REG.7=0 'Global Weak Pull up (or use WPU=%00000011)
CMCON=7 'comparators off
PAUSE 100
MAIN:
GPIO.2=1
PAUSE 2166 '2.166s
PAUSEUS 667 '0.000667s
GPIO.2=0
PAUSE 500 '0.5s
GOTO MAIN
END
Anyone got any ideas why the timing is so inaccurate?
It's even less precise than the 555 RC circuit I built years ago to do a similar job!
Many thanks.
Bookmarks