Dave
Always wear safety glasses while programming.
If you need to run at 4Mhz on the internal OSC, put this in your code.
I have a development board that runs at 40Mhz on a 10Mhz XTAL + PLL, but sometimes I need to slow things down to 4Mhz and run on the internal oscillator to see how they will run on "little" parts. This code does the trick.Code:ASM movlw 0x62 ; %0110 0010 = 4 Mhz, internal osc block movwf OSCCON movlw 0x80 ; %1000 0000 = PLL disabled movwf OSCTUNE ENDASM
Charles Linquist
I was thinking of a routine that could detect the clock speed the pic is running at
so that then the pic program could adjust serial speed, etc accordingly.
Make a delay loop in picbasic and count the number of ticks a hardware timer
makes during the delay loop.. and then the hardware timer value will be
different for different clock speeds.
Art, What would you use as a reference in that situation?
Dave Purola,
N8NTA
If you have a PIC that supports Internal/External Oscillator Switchover then you shouldn't need a firmware solution to determine osc speed. You already know what it should be after you write to OSCCON & flip the System Clock Select bit.
If you have one running on the internal oscillator, and you need to calibrate it, then Microchip has a few app notes for this using TMR1 with an external 32.768kHz watch type crystal. Or you could just output the internal clock on OSC2/CLKO and test it with an O-scope.
Lets say you have a 4MHz clock and you set a delay of 1mS (1000us). A timer (without pre/post scaler) will count to 1000 for the duration of the delay.
Now drop the clock the 1MHz. The timer will now count to 250 (1000/4) each mS. However, the delay will increase to 4mS due to the slower clock, so the timer will again count to 1000.
Bookmarks