Page 1 of 1
Port from 328n to 328l
Posted: 05 February 2010, 7:22 AM
by FFMan
Another newbie question.
I think the documentation suggest that the main difference between the 328n and the 328l is the clock speed and voltage range. Therefore for development, is it sufficient to clock down a 328n to 328l speed and if all runs ok assume the transition to a 328l will work or are there other factors to consider ?
thanks
Re: Port from 328n to 328l
Posted: 05 February 2010, 8:12 AM
by dkinzer
FFMan wrote:[T]he documentation suggest that the main difference between the 328n and the 328l is the clock speed and voltage range.
That is the only difference. The 328l runs at 7.37MHz solely to allow it to be powered as low as 2.7V (the brownout detection level).
FFMan wrote:s it sufficient to clock down a 328n to 328l speed and if all runs ok
You cannot run ZX devices at any speed other than their specified speed. The code for each device sets up USART and timer registers based on the specified speed. If you run it at a different frequency, nothing that is time-dependent (e.g. serial I/O, RTC, etc.) will work properly.
FFMan wrote:[A]re there other factors to consider?
In most cases, simply re-compiling for a different ZX target device is all that is necessary. There are a few exceptions, however. For example, the units of InputCapture() and OutputCapture() are derived from I/O Timer ticks (using a divide-by-1 prescaler by default). Since the crystal frequency of a ZX-328l is one half that of a ZX-328n, it follows that the units of InputCapture() and OutputCapture() values are twice as large. Most ZX System Library routines automatically adapt to the operating frequency to produce consistent results but a few, like InputCapture() and OutputCapture(), do not.
If your code uses a hard-coded frequency value for any computations, it will be incorrect for a ZX-328l. You can re-write your code to automatically adapt to the ZX operating frequency by using the built-in constant Register.CPUFrequency.
In cases where you need different code for different ZX devices, you can use conditional compilation directives to automatically select the correct code for each device.Code: Select all
#if Option.TargetDevice = "ZX328n"
' put code here for the ZX-328n
#elseif Option.TargetDevice = "ZX328l"
' put code here for the ZX-328l
#else
#error need device-specific code
#endif