Ok, after a little experimentation today, finding the frequency without any use of EEPROM at all is really this easy:
Then you have a number in wrtcount that represents the crystal frequency i.e. a couple of values either side of 25 = 20MHz.Code:' DEFINE OSC 20 ‘needed so the 100ms pause period is known ' if status.bit4 = 1 then 'was not reset by watchdog for percount = 0 to 255 'do eeprom writes until wdt reset pause 100 ' @ MOVF _percount ,W ;copy counter value to timer low byte @ MOVWF TMR1L ;load timer with count value next percount ' makereset: 'failsafe to make reset occur goto makereset ' ' else 'hardware was reset by watchdog @ clrwdt ; @ MOVF TMR1L ,W ;copy counter value to timer low byte @ MOVWF _wrtcount ;reload timer with correct value endif ' '
This is with the power timer also set, but I doubt that matters as the pic isn’t doing anything in power timer period.
In any case, it’s very handy to know that if you’re not using Timer1,
you have an ordinary word variable that survives WDT for certain.
If your program was going to use Timer1 after this, the values should probably be reset to zero, then the clock started.
DT’s Elapsed Timer code does have a Reset feature which probably does this as well as clearing it's real time variables.




Bookmarks