April Fools' Pic Project

Thread Starter

Art

Joined Sep 10, 2007
806
Hi Guys :)
Here's a pic program that can tell what osc frequency is clocking it, and adjust accordingly to make an LED flash at one pulse per second.
Cheers, Art.

 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
Actually, many PIC's have two, independent oscillators today. One is fixed and the other is variable. Using the fixed (lower frequency one) oscillator to determine another frequency, such as the other internal oscillator shouldn't be that difficult. Of course, I realize this was not a serious post.

John
 

Thread Starter

Art

Joined Sep 10, 2007
806
You realised wrong ;)
It’s a 16F628A configured for HS (not just running from internal RC osc).
I could have, but did not, initially made it run the LED at a freq representative of the clock freq
prior to flashing the LED at 1 Hz.
Also, I accidentally uploaded in SD... fixing that now.

It’s real and everything about the circuit is is as I say it is.
The 1 Hz pulse is driven by timer1 overflow interrupt.

Of course, I realize this was not a serious post.

John
 

Alberto

Joined Nov 7, 2008
169
Art, let me give a try. You generate a PWM out to a fixed frequency for a given cristal and you monitor it using the internal timer. If the PWM frequency is higher or lower than the expected one then the program adjusts the time interval to keep the flashing rate of 1 hertz costant.
Am I close?
Cheers

Alberto
 
Last edited:

Thread Starter

Art

Joined Sep 10, 2007
806
Like I said it not program...rather a video file
I’m not sure if you’re saying it’s fake, or the program is simple?
Yes it’s a program only functional to demonstrate what’s happening with no other purpose.

@ Alberto:
I don’t know how you’d look at the PWM channel without another wire connected to the pic,
or if you can even generate hardware PWM with the internal clock when an external clock is selected for clocking the pic.
I’m not saying it’s not possible, I haven’t checked datasheets in that regard.

It was figured out on another forum, so in English;

Program starts.

Check status bit 4 to see if the pic is starting after watchdog timer reset or cold powerup.

If it’s a cold start, enter a loop that does not reset the watchdog, but writes a zero value to on-chip EEPROM every 100ms
(calculated at 20MHz) and increments a variable addressing the on-chip EEPROM location.
The watchdog timer will reset the pic well before 30 locations are written so long as the pic is running 25MHz or under.

If it was started after a watchdog timer reset, count the number of zero values on on-chip EEPROM,
and populate the on-chip EEPROM with all 0xFF values again for next time.
From now on, reset the watchdog timer so it will not reset again.
Compare the count of zero values with a lookup table to find the crystal frequency.

Set the timer1 preload values accordingly to time 100Hz interrupt so seconds can be counted.
Cheers, Art.
 

Thread Starter

Art

Joined Sep 10, 2007
806
Well obviously the idea was to figure it out.
There is more than one way. This is PBP with some inline assembler
(just the part to get a count from which the clock freq can be determined)
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 '
'
 
Top