Port from 328n to 328l

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Port from 328n to 328l

Post 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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Port from 328n to 328l

Post 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
- Don Kinzer
Post Reply