HC9S12

The following pages are code examples for the Freescale 9S12 microcontroller. The C compiler I use is ICC12. These pages are without copyright or guarantee

32x32 bit divide

The ICC12 library 32-bit by 32-bit divide requires more than 2500 cycles.  It is your typical shift-subtract algorithm that does not make use of the efficiencies of the divide routines in the HC12 instruction set.  After trolling the net for alternatives I found one for the 6.x version of the compiler (dragonsgate.net/pipermail/icc-mot/2002-September/000041.html).  After a fair bit of rework for the 7.x stackframe I've come up with the following function that executes in 314 cycles or less.  Random tests have run successfully since May 2010.  Note that the arguments of uldiv must point to separate memory locations (ie: uldiv(&a, &b, &a) will cause an error).

32x32 bit multiply

The ICC12 library doesn't supply a 64 bit result for it's long multiply.   This routine is an extension of the existing 32x32 library function and requires the user to define a uint64 type.  For a 9S12 running at 24MHz the function executes in 5.5usec.

ATD Example

This implementation of the S12ATD10B8C module is suitable for a system requiring a single ATD channel only. Reads automatically kick off a new sequence of eight conversions of the defined channel with the result being the average of those eight conversions. The maximum rate for updated data is approximately 20KHz.

Syndicate content