Changing clock frequency

maitchy

Member
1. (Minor observation):
The documentation says (p80, manual1):

When downloading new programs, you must ensure the
correct frequency (View>Options>Mode) is used to match the last program
running in the PICAXE chip. If in doubt perform a ‘hard-reset’ at 4Hz.

I think it can download a new program to my 14M no matter whether it was last running at 4 or 8MHz.

2. (Major question):
If I have a 28X1 and use a resonator (or external xtal clock oscillator??) faster than 4MHz, does "setfreq m4" always set it to the frequency of the resonator, while 'setfreq m8" sets it to twice the frequency? Otherwise, should I get an 8 or 16MHz resonator if I want 16MHz (I presume that a device that is capable of 20MHz should not actually be run at 20 because I'd never be able to program the thing?? I notice the speed selector disappears when selecting 28X1 parts in View->Options->Mode, so I'm a bit confused as to what is supported in the way of downloads... page 68 of the manual doesn't help me see what can be done).
 

BCJKiwi

Senior Member
This was the definitive response from Technical when this issue was raised previously:-

There is still some confusion here as you are making comments such as "downloads only work with the programmer terminal set at 9600". A new program download is completely unrelated to the Serial Terminal baud rate.

In the case of all current chips (that have an internal resonator)
1) A download will always work at 4MHz.
2) When any PICAXE chip resets, it always checks for a new download before starting to run its internal program. Therefore a hard-reset will always function at 4MHz, because no setfreq command would yet have been processed.
3) If a new download attempt ever fails (e.g. because the computer and chip are trying to communicate at different baudrates) the PICAXE chip automatically resets. It will then therefore attempt to communicate again (but now at 4MHz) if the download signal is still present after the reset.
4) #freq is simply a directive which is a shortcut method of changing the View>Options>Mode>Options (clock speed) menu. We'll use #freq here, but you could use the menu instead. Remember all the # directives are simply instructions to the computer, they are not part of the downloaded PICAXE program.
5) If the PICAXE program contains a command such as 'setfreq m8' the chip will run at twice normal speed after the command has processed. This means that communication with the computer in certain serial commands (particularly 'debug') will not synchronise if the computer does not know the chip is now running at double speed. Adding a #freq directive into the program tells the computer the correct speed to use, and so, for instance, the debug software window will correctly synchronize.
6) The Serial Teminal is a feature separate to downloads. It is just a tool for the end user to be able to display serial command data (serout, hserout, sertxd etc) on the computer screen. The baud rate of the Serial Terminal must match the baud rate set in the serout/hserout command within the PICAXE program. For sertxd commands the baud rate is fixed at 4800 at 4MHz, 9600 at 8MHz etc.

For the case of the older 28A, 28X, 40X:
These chips had only an external resonator which provided a fixed speed of 4, 8 or 16MHz. In these cases the #freq directive must always match the external resonator value, or no feature (even a download) would function correctly, as the computer and chip would try to operate at different speeds.
__________________
PICAXE Technical Support
 
Top