Previous

Next

Bottom

Contents

Glossary

Index

 

Persistor CF1 User's Manual

Configurable Timer Module Wrapper Functions

July 1998

Revision 1.01

 Persistor Instruments Inc.
© 1998 All rights reserved.

Quick Reference Table

Double Action Submodule Functions

CTFRInterruptFunction

CTMSetPrescale

CTDAClearEventFlag

CTFRInterruptLevel

CTMTimeBaseReg

CTDADataRegA

CTFRSelectClockSource

Single Action Submodule Functions

CTDADataRegB

Modulus Counter Submodule Functions

CTSAClearEventFlag

CTDAEdgeSelect

CTMCClearCOFFlag

CTSADataReg

CTDAFlipFlops

CTMCCounterReg

CTSAEdgeSelect

CTDAGetEventFlag

CTMCDriveTimeBase

CTSAFlipFlop

CTDAInterruptFunction

CTMCGetCOFFlag

CTSAGetEventFlag

CTDAInterruptLevel

CTMCInterruptFunction

CTSAInterruptEnable

CTDAModeSelect

CTMCInterruptLevel

CTSAInterruptFunction

CTDAReloadOPWM

CTMCModulusReg

CTSAInterruptLevel

CTDASetupOPWM

CTMCSelectClockSource

CTSAModeSelect

CTDATimeBaseBusSelect

CTMCSelectEdges

CTSATimeBaseBusSelect

CTDAWiredOrMode

General CTM Functions

Freerunning Counter Submodule Functions

CTMGetPrescaleP6

CTFRClearCOFFlag

CTMInit

CTFRCounterReg

CTMPrescaleIsDiv3

CTFRDriveTimeBase

CTMPrescalerRun

CTFRGetCOFFlag

CTMRun

   

Background

The Configurable Timer Module, hereafter CTM, is an incredibly useful submodule of the Motorola 68338. It can be used for things such as period measurement, frequency counting, pulse width measurement and generation, pulse counting and a multitude of other applications that even we haven't thought of yet. This provides a great opportunity to you, the developer, but not without a price. While the reference material provided here is intended to be a complete function reference, explaining the detailed functionality of the CTM's various and diverse submodules is far beyond the scope of this manual. The CTM is quite complex, and it is almost certain that you will need to have at least a passing familiarity with the entire Motorola provided CTM reference.

This section provides the documentation for our low level interface functions.

Acronyms

There are many different types of submodules in the CTM, and they all have long, multiword names. In an effort to reduce the overall length and increase the signal-to-noise ration of this documentation, we have, with respect to context, abbreviated where possible. Any abbreviations used will be the same as those used in the Motorola documentation, if they appear in the Motorola documentation. A quick list of the more oft used acronyms follows:

CTM - Configurable Timer Module
BIUSM - Bus Interface Unit Submodule
IMB - Inter-Module Bus
CPSM - Counter Prescaler Submodule
FCSM - Freerunning Counter Submodule
MCSM - Modulus Counter Submodule
COF - Counter Overflow Flag
SASM - Single Action Submodule
DASM - Double Action Submodule

CTDAClearEventFlag -- Clear the counter event flag

Each Double Action Submodule that is set up to perform a given task will have an event flag to indicate whether the event it has been set up to perform has occurred. This function clears this flag to 0.

Prototype:

void CTDAClearEventFlag (DoubleActionID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which DASM you wish to clear the event flag of. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29

Notes:

Timing:

Timing-TBD

CTDADataRegA -- Return pointer to counter's data register A

This function returns a pointer to the data register for channel A of the specified DASM. The following excerpt from the CTM manual describes the register's functions in various modes: (mode descriptions can be found at the CTDAModeSelect function reference.)

DASMA is the data register associated with channel A; its use varies with the different modes of operation:

Prototype:

vushort *CTDADataRegA (DoubleActionID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies the DASM whose data register address will be returned. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29

Returns:

Returns a pointer to the DASM's channel A data register.

Notes:

Timing:

Timing-TBD

CTDADataRegB -- Return pointer to counter's data register B

This function returns a pointer to the data register for channel A of the specified DASM. The following excerpt from the CTM manual describes the register's functions in various modes: (mode descriptions can be found at the CTDAModeSelect function reference.)

Prototype:

vushort *CTDADataRegB (DoubleActionID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies the DASM whose data register address will be returned. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29

Returns:

Returns a pointer to the DASM's channel B data register.

Notes:

Timing:

Timing-TBD

CTDAEdgeSelect -- Select the counter clock edge

The action of this function depends on the current mode of the DASM. In Input Pulse Width Measurement mode, setting this to TRUE causes Channel A to capture on the falling edge and B to capture on the rising edge and vice versa for FALSE. In Input Period Measurement and Input Compare modes, This bit controls the edge sensitivity of Channel A. if it is TRUE in one of these modes, then Channel A captures on the falling edge and if it is FALSE it captures on the rising edge. In Output Compare B, Output Compare AB, and Output Pulse Width Modulation modes the edge polarity bit is used to set the voltage level on the output pin. If this bit is true, the complement of the output flip-flop logic level appears on the output pin: a compare on channel A resets the output pin; a compare on channel B sets the output pin. If it is FALSE, the output flip-flop logic level appears on the output pin: a compare on channel A sets the output pin, a compare on channel B resets the output pin.

Prototype:

void CTDAEdgeSelect (DoubleActionID sm, bool posB);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies the DASM for which you wish to select the counter edge. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
posB depends heavily on mode, see description above.

Notes:

Timing:

Timing-TBD

CTDAFlipFlops -- Force the counter flip flop

This function sets one or both of the FORCE bits on the specified DASM. Setting FORCE bit A causes channel A of the DASM to act as if the event associated with channel A has occurred, but the flag bit is not set. Similarly, writing to FORCE bit B causes channel B of the DASM to act as if the event associated with channel B has occurred, but the flag bit is not set. This only has meaning in the Output Compare B, Output Compare AB, and Output Pulse Width Modulation modes.

Prototype:

void CTDAFlipFlops (DoubleActionID sm, bool forceA, bool forceB);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies the DASM for which you wish to force the flip flop. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
forceA is TRUE if you wish to set the channel A force bit
forceB is TRUE if you wish to set the channel B force bit

Notes:

Clearing the bits to 0 has no effect in any mode.

Timing:

Timing-TBD

CTDAGetEventFlag -- Return the counter event flag

Each Double Action Submodule that is set up to perform a given task will have an event flag to indicate whether the event it has been set up to perform or wait for has occurred. This function returns the current state of this flag.

Prototype:

bool CTDAGetEventFlag (DoubleActionID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which DASM you wish to examine. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29

Returns:

Returns a boolean that reflects the state of the specified DASM's event flag.

Notes:

Timing:

Timing-TBD

CTDAInterruptFunction -- Insert the counter interrupt hander

This function installs an interrupt service routine for any interrupts generated by the specified DASM. This service routine should be a C function, taking no parameters and returning void, that was prototyped and declared with the IEV_C_PROTO and IEV_C_FUNCT macros discussed in detail in the Interrupt and Exception Vectors section of the reference manual. It can also be an assembly function.

Prototype:

void CTDAInterruptFunction (DoubleActionID sm, vfptr *ifp);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which DASM you wish to set the interrupt function for. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
ifp is either a pointer to an IEVCWrapper structure that is implicitly created by the IEV_C_FUNCT declaration macro or it is a function pointer to an assembly function.

Notes:

Timing:

Timing-TBD

CTDAInterruptLevel -- Set the counter IRQ and ARB levels

Each Double Action Submodule(SASM) is capable of generating an interrupt. If enabled, the DASM will generate an interrupt for its specified event. This function allows you to specify the interrupt level upon which the interrupt will be generated if it is enabled. It also allows you to select one of two sublevels of interrupt arbitration. Each submodule of the CTM is capable of generating an interrupt on any interrupt request level. However, while 16 levels of interlevel arbitration are available on the intermodule bus, the CTM sets the low three bits of the arbitration number for the whole CTM in the Bus Interface Unit Submodule configuration register. Each other submodule can set the high bit of the arbitration "nibble" which essentially offers two possible arbitration numbers to each submodule in the CTM, one relatively high, and one relatively low.

Prototype:

void CTDAInterruptLevel (DoubleActionID sm, short il, short iarb3);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which DASM you wish to set the interrupt level for. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
il is the systemwide interrupt request level at which the specified DASM's interrupt will execute
iarb3 represents the high bit of the interrupt arbitration number. (can be 0 or 1)

Notes:

Timing:

Timing-TBD

CTDAModeSelect -- Select the counter operating mode

This function selects the operating mode of the specified DASM. The following typedef illustrates all of the available modes and their DASMModeIDs:

typedef enum
    {
    DASMDisable = 0,    
    DASMIPWM,       // Input Pulse Width Measurement
    DASMIPM,        // Input Period Measurement
    DASMIC,         // Input Capture
    DASMOCB,        // Output Compare Flag on Channel B
    DASMOCAB,       // Output Compare Flag on A and B
                    // 6 and 7 Reserved.
    DASMOPWM16 = 8, // Output PWM 16 Bit Resolution
    DASMOPWM15,     // Output PWM 15 Bit Resolution
    DASMOPWM14,     // Output PWM 14 Bit Resolution
    DASMOPWM13,     // Output PWM 13 Bit Resolution
    DASMOPWM12,     // Output PWM 12 Bit Resolution
    DASMOPWM11,     // Output PWM 11 Bit Resolution
    DASMOPWM9,      // Output PWM 9 Bit Resolution
    DASMOPWM7,      // Output PWM 7 Bit Resolution
    } DASMModeID;

 



Prototype:

vushort *CTDAModeSelect (DoubleActionID sm, DASMModeID mode);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies the DASM for which you wish to select the mode. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
mode is a DASMModeID, the options for which are described above.

Returns:

Returns a pointer to the specified DASM's Status/Interrupt/Control register.

Notes:

Timing:

Timing-TBD

CTDAReloadOPWM -- Reload double action OPWM output

This function allows you to modify the duty cycle and pulse position of a PWM generator setup by the CTDASetupOPWM function. This function allows you to specify new counter-relative positions of the leading and trailing edges of the pulse.

Prototype:

void CTDAReloadOPWM (short sm, ushort le, ushort te);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which DASM you wish to modify an existing PWM generation on. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
le indicates the counter value in the period where the leading edge of the pulse should appear.
te indicates the counter value in the period where the trailing edge of the pulse should appear.

Notes:

See the CTDASetupOPWM function for more information.

Timing:

Timing-TBD

CTDASetupOPWM -- Setup double action OPWM output

This function provides a higher level interface to the common task of Pulse Width Modulation generation. See the parameter description for more information on usage.

Prototype:

void CTDASetupOPWM (DoubleActionID sm, bool busB, bool posB, short bits, ushort le, ushort te);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which DASM you wish to set up PWM generation on. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
busB indicates whether the DASM specified by sm is clocked off of its A bus or B bus.
posB selects the edge polarity that triggers the counter if you have independently configured the DASM to be externally triggered.
bits indicates how many bits of resolution the PWM generator should use. (1,9,11,12,13,14,15,16)
le indicates the counter value in the period where the leading edge of the pulse should appear.
te indicates the counter value in the period where the trailing edge of the pulse should appear.

Notes:

The result of this function depends on many factors, primarily the defaults that are compiled into the CTMInit function. The location (physical location on the CTM6 silicon die) of the DASM you pick to perform this function determines which pair of counters it will have access to. CTMInit has preloaded the four\ counters with prescaler clock rates as follows: MCSM30 gets SYSCLK/2 and MCSM31 gets SYSCLK/16 These two are on bus A and B respectively and can be accessed by DASM26, DASM27, DASM28 and DASM29. MCSM2 get SYSCLK/32 and FCSM get SYSCLK/128 and they are on bus A and B respectively and can be accessed by all remaining DASMs.

Timing:

Timing-TBD

CTDATimeBaseBusSelect -- Select counters time base

This function selects which time base bus the single action submodule should be clocked from. Each DASM has access to only one pair of time buses and thus can only be driven by certain counters.

Prototype:

void CTDATimeBaseBusSelect (DoubleActionID sm, bool busB);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies the DASM for which you wish to choose a time base bus. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
busB is TRUE if the SASM should be clocked from bus B of the pair that it has access to. If it is FALSE it is driven from bus A of the pair it has access to.

Notes:

Timing:

Timing-TBD

CTDAWiredOrMode -- Select wired or output mode

This function has varying effects depending on the mode of the DASM in question. In Output Compare B, Output Compare AB, and Output Pulse Width Modulation modes, the Wired OR bit select whether the output buffer ifs configured for open-drain or totem-pole operation. In all other DASM modes, the Wired OR bit has no effect. One possible use of this would be if two submodules (such as DASM29 and SASM12A) have their outputs wired together and you wish to use them to create some complex waveform. If the output of the DASM were wired in totem pole configuration, one of the output drivers would be ruined if one pulled low while the other pulled high, but if the output is wired open drain, then either channel can pull low without causing high current flows.

Prototype:

void CTDAWiredOrMode (DoubleActionID sm, bool wom);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies the DASM for which you wish to set the output mode for. Valid DoubleActionID: DASM4, DASM5, DASM6, DASM7, DASM8, DASM9, DASM10, DASM26, DASM27, DASM28, DASM29
wom is TRUE if the output buffer should be open-drain, FALSE if it should be in totem pole configuration.

Notes:

Open-drain outputs often need pull-ups.

Timing:

Timing-TBD

CTFRClearCOFFlag -- Clear the free running counter overflow flag

The CTM6 module of the MC68CK338 contains one Freerunning Counter Submodule (FCSM). This counter, once the CTM has been started simply counts from 0 to 65535 (16 bits) and loops. When the counter loops, its counter overflow flag(COF) is set. This function clears the freerunning counter's overflow flag to 0.

Prototype:

void CTFRClearCOFFlag (void);

Definition:

#include <cf1bios.h>

Notes:

Timing:

Timing-TBD

CTFRCounterReg -- Return pointer to free running counter

This function returns a pointer to the counter register of the freerunning counter so that your program may see the value of the counter at any given time.

Prototype:

vushort *CTFRCounterReg (void);

Definition:

#include <cf1bios.h>

Returns:

A pointer to the 16 bit counter register.

Notes:

You can load a value into the counter by writing to this register.

Timing:

Timing-TBD

CTFRDriveTimeBase -- FRC drives and select time base A or B

This function assigns which of the two time base busses that are available to the freerunning counter should be driven. There are four time base busses in the CTM but any submodule only has access to two of those four. Since the submodules only have access to two of the four they are always referred to as bus a and bus b. the combination of A and B will always be either the respective pair 1 & 2 or the respective pair 3 & 4. This is an oversimplified explanation. It is highly recommended that you familiarize yourself with the "silicon geometry" and module configuration of the CTM6 by referring to page 79 of the Motorola MC68CK338 technical summary (68338ckts.pdf) which should have been included with this documentation.

Prototype:

void CTFRDriveTimeBase (bool drive, bool busB);

Definition:

#include <cf1bios.h>

Inputs:

drive is a boolean that indicates whether you wish to have the free running counter drive the specified time base bus. If it is FALSE, any bus previously being driven will no longer be driven, and busB will be ignored.
busB is TRUE if the freerunning counter should drive bus B, FALSE to drive bus A

Notes:

Timing:

Timing-TBD

CTFRGetCOFFlag -- Return the free running counter overflow flag

The CTM6 module of the MC68CK338 contains one Freerunning Counter Submodule (FCSM). This counter, once the CTM has been started simply counts from 0 to 65535 (16 bits) and loops. When the counter loops, its counter overflow flag(COF) is set. This function returns the current state of this flag.

Prototype:

bool CTFRGetCOFFlag (void);

Definition:

#include <cf1bios.h>

Returns:

Returns TRUE if the flag is set. FALSE otherwise.

Notes:

Timing:

Timing-TBD

CTFRInterruptFunction -- Insert the free running counter interrupt hander

This function installs an interrupt service routine for any interrupts generated by the freerunning counter. This service routine must be a C function, taking no parameters and returning void, that was prototyped and declared with the IEV_C_PROTO and IEV_C_FUNCT macros discussed in detail in the Interrupt and Exception Vectors section of the reference manual.

Prototype:

void CTFRInterruptFunction (vfptr *ifp);

Definition:

#include <cf1bios.h>

Inputs:

ifp is either a pointer to an IEVCWrapper structure that is implicitly created by the IEV_C_FUNCT declaration macro or it is a function pointer to an assembly function.

Notes:

You will also need to set up the interrupt level at which this routine will execute using the CTFRInterruptLevel function. Interrupts on the freerunning counter are disabled by default.

Timing:

Timing-TBD

CTFRInterruptLevel -- Set the free running counter IRQ and ARB levels

The Freerunning Counter Submodule (FCSM) is capable of generating an interrupt. This counter, once the CTM has been started simply counts from 0 to 65535 (16 bits) and loops. When the counter loops, if the option is enabled, an interrupt will be generated. This function allows you to specify the interrupt level upon which the interrupt will be generated if it is enabled. It also allows you to select one of two sublevels of interrupt arbitration. Each submodule of the CTM is capable of generating an interrupt on any interrupt request level. However, while 16 levels of interlevel arbitration are available on the intermodule bus, the CTM sets the low three bits of the arbitration number for the whole CTM in the Bus Interface Unit Submodule configuration register. Each other submodule can set the high bit of the arbitration "nibble" which essentially offers two possible arbitration numbers to each submodule in the CTM, one relatively high, and one relatively low.

Prototype:

void CTFRInterruptLevel (short il, short iarb3);

Definition:

#include <cf1bios.h>

Inputs:

il is the systemwide interrupt request level at which the freerunning counter's interrupt will execute
iarb3 represents the high bit of the interrupt arbitration number. (can be 0 or 1)

Returns:

Notes:

On reset the interrupt level of the Freerunning Counter Submodule is 0, meaning that it will not generate interrupts.

Timing:

Timing-TBD

CTFRSelectClockSource -- Select free running counter clock source

This function allows you to select the source from which the freerunning counter will be clocked. This determines how fast the counter will increment. There are six internal clock lines that can be chosen or the counter can be clocked off of either edge of an external clock. Any external clock may not be of a higher frequency that 1/4 the frequency of the system clock. For more information on the internal clocks available to the counters please see the clock rate description in the CTMSetPrescale function reference.

Prototype:

vushort *CTFRSelectClockSource (CounterClockSourceID clksel);

Definition:

#include <cf1bios.h>

Inputs:

clksel is a CounterClockSourceID that is one of the following: PCLK1, PCLK2, PCLK3, PCLK4, PCLK5, PCLK6, CTMCFallingEdge, CTMCRisingEdge

Returns:

Notes:

Timing:

Timing-TBD

CTMCClearCOFFlag -- Clear the modulus counter overflow flag

The CTM6 module of the MC68CK338 contains three Modulus Counter Submodules (MCSM). This counter, once the CTM has been started counts from a prespecified value to 65535 (16 bits) and loops. When the counter loops, its counter overflow flag(COF) is set. This function clears the flag of the specified counter to 0. If the counter loops more than once before this function is called, then the COF will remain set.

Prototype:

void CTMCClearCOFFlag(ModulusCounterID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to check the overflow flag of. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31

Notes:

Timing:

Timing-TBD

CTMCCounterReg -- Return pointer to modulus counter's counter register

This function returns a pointer to the counter register of the specified modulus counter so that your program may see the value of the counter at any given time.

Prototype:

vushort *CTMCCounterReg (ModulusCounterID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to return the register of. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31

Returns:

A pointer to the 16 bit register.

Notes:

You can load a value into the counter by writing to this register.

Timing:

Timing-TBD

CTMCDriveTimeBase -- MC drives and select time base A or B

This function assigns which of the two time base busses that are available to the specified modulus counter should be driven. There are four time base busses in the CTM but any submodule only has access to two of those four. Since the submodules only have access to two of the four they are always referred to as bus a and bus b. The combination of A and B will always be either the respective pair 1 & 2 or the respective pair 3 & 4. This is an oversimplified explanation. It is highly recommended that you familiarize yourself with the "silicon geometry" and module configuration of the CTM6 by referring to page 79 of the Motorola MC68CK338 technical summary (68338ckts.pdf) which should have been included with this documentation.

Prototype:

void CTMCDriveTimeBase (ModulusCounterID sm, bool drive, bool busB);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to specify bus driving information for. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31
drive is a boolean that indicates whether you wish to have the free running counter drive the specified time base bus. If it is FALSE, any bus previously being driven will no longer be driven, and busB will be ignored.
busB is TRUE if the freerunning counter should drive bus B, FALSE to drive bus A

Notes:

Please refer to the MC68CK338 Technical summary (68338ckts.pdf) for information about which counters can interact on which time base busses.

Timing:

Timing-TBD

CTMCGetCOFFlag -- Return the modulus counter overflow flag

The CTM6 module of the MC68CK338 contains three Modulus Counter Submodules (MCSM). This counter, once the CTM has been started counts from a prespecified value to 65535 (16 bits) and loops. When the counter loops, its counter overflow flag(COF) is set. This function returns the current state of this flag.

Prototype:

bool CTMCGetCOFFlag(ModulusCounterID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to check the overflow flag of. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31

Returns:

Returns the state of the counter overflow flag of the specified modulus counter.

Notes:

Timing:

Timing-TBD

CTMCInterruptFunction -- Insert the modulus counter interrupt hander

This function installs an interrupt service routine for any interrupts generated by the specified modulus counter. This service routine must be a C function, taking no parameters and returning void, that was prototyped and declared with the IEV_C_PROTO and IEV_C_FUNCT macros discussed in detail in the Interrupt and Exception Vectors section of the reference manual.

Prototype:

void CTMCInterruptFunction (ModulusCounterID sm, vfptr *ifp);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to specify the interrupt service routine for. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31
ifp is either a pointer to an IEVCWrapper structure that is implicitly created by the IEV_C_FUNCT declaration macro or it is a function pointer to an assembly function.

Notes:

You will also need to set up the interrupt level at which this routine will execute using the CTMCInterruptLevel function. Interrupts on the modulus counters are disabled by default.

Timing:

Timing-TBD

CTMCInterruptLevel -- Set the modulus counter IRQ and ARB levels

The Modulus Counter Submodule (MCSM) is capable of generating an interrupt. This counter, once the CTM has been started counts from a prespecified value to 65535 (16 bits) and loops. When the counter loops, if the option is enabled, an interrupt will be generated. This function allows you to specify the interrupt level upon which the interrupt will be generated if it is enabled. It also allows you to select one of two sublevels of interrupt arbitration. Each submodule of the CTM is capable of generating an interrupt on any interrupt request level. However, while 16 levels of interlevel arbitration are available on the intermodule bus, the CTM sets the low three bits of the arbitration number for the whole CTM in the Bus Interface Unit Submodule configuration register. Each other submodule can set the high bit of the arbitration "nibble" which essentially offers two possible arbitration numbers to each submodule in the CTM, one relatively high, and one relatively low.

Prototype:

void CTMCInterruptLevel(ModulusCounterID sm, short il, short iarb3);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to assign the interrupt level for. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31
il is the systemwide interrupt request level at which the specified modulus counter's interrupt will execute
iarb3 represents the high bit of the interrupt arbitration number. (can be 0 or 1)

Notes:

Timing:

Timing-TBD

CTMCModulusReg -- Return pointer to modulus counter's modulus register

This function returns a pointer to the modulus (or "load") register of the specified modulus counter so that your program may see the value of the counter at any given time. A modulus counter stats at a certain value and counts up to 0xFF. This register contains and can be used to set the load value where the counter starts each iteration.

Prototype:

vushort *CTMCModulusReg (ModulusCounterID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to return the load register of. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31

Returns:

A pointer to the 16 bit modulus register.

Notes:

You can load a new modulus value into this register by writing to this pointer.

Timing:

Timing-TBD

CTMCSelectClockSource -- Select modulus counter clock source

This function allows you to select the source from which the specified modulus counter will be clocked. This determines how fast the counter will increment. There are six internal clock lines that can be chosen or the counter can be clocked off of either edge of an external clock. Any external clock may not be of a higher frequency that 1/4 the frequency of the system clock. For more information on the internal clocks available to the counters please see the clock rate description in the CTMSetPrescale function reference.

Prototype:

vushort *CTMCSelectClockSource (ModulusCounterID sm, CounterClockSourceID clksel);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to select the clock source for. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31
clksel is a CounterClockSourceID that is one of the following: PCLK1, PCLK2, PCLK3, PCLK4, PCLK5, PCLK6, CTMCFallingEdge, CTMCRisingEdge

Returns:

Notes:

Timing:

Timing-TBD

CTMCSelectEdges -- Select modulus counter load pin edge sensitivity

The Modulus Counter Submodule (MCSM) has two registers, one that holds the starting value and one that is the counter. Unlike the freerunning counter, the MCSM starts counting at the value that is in the load register. This normally happens when the counter loops at 65535, but can also be triggered by an external pin. The pin number depends upon which MCSM is chosen. This pin acts as a "reset" for the modulus counter. The overflow flag is not set when this type of reset occurs, but similarly to an overflow, the counter begins counting at the load value again. This pin is referred to as CTML in Motorola literature.

Prototype:

void CTMCSelectEdges (ModulusCounterID sm, bool pos, bool neg);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the three modulus counters to set the load characteristics of. Valid ModulusCounterIDs: MCSM2, MCSM30, MCSM31
pos is TRUE if you wish to have a reset triggered on a rising edge on the CTML
neg is TRUE if you wish to have a reset triggered on a falling edge on the CTML

Notes:

Timing:

Timing-TBD

CTMGetPrescaleP6 -- Return the PCLK 6 subdivisor selection

This function exists to report the divisor of the prescaler on PCLK6. PCLK6 provides a choice of subdivisors and this function tells which one is in use. For more information concerning the division of the system clock and the prescaler in general, see CTMSetPrescale

Prototype:

P6DivisorID CTMGetPrescaleP6 (void);

Definition:

#include <cf1bios.h>

Returns:

Notes:

At system startup, the PCLK6 subdivisor us P6Div64.

Timing:

Timing-TBD

CTMInit -- Initialize the counter/timer module

This function will never need to be called by a user application is called by the BIOS startup routine on power-on or reset. It loads the essential registers with appropriate defaults and makes appropriate time base bus assignments for the various modules.

Prototype:

void CTMInit (void);

Definition:

#include <cf1bios.h>

Notes:

Timing:

Timing-TBD

CTMPrescaleIsDiv3 -- Return the prescaler divide by three flag

This function exists to report the divisor of the pre-pre-scaler. The system clock is either divided by 2 or 3 in the pre-pre-scaler. For more information concerning the division of the system clock and the prescaler in general, see CTMSetPrescale

Prototype:

CPSMDivisor CTMPrescaleIsDiv3 (void);

Definition:

#include <cf1bios.h>

Returns:

Returns DivideBy3 if the pre-pre-scaler is dividing by 3, DivideBy2 if it is dividing by 2.

Notes:

At system startup the CPSMDivisor is set to DivideBy2

Timing:

Timing-TBD

CTMPrescalerRun -- Start or stop the prescaler from running

This function turns the prescaler (CPSM) on and off as indicated. When the CPSM is off, the counters will not run.

Prototype:

void CTMPrescalerRun (bool run);

Definition:

#include <cf1bios.h>

Inputs:

run is a boolean that is TRUE if the CPSM should be running.

Notes:

Timing:

Timing-TBD

CTMRun -- Start or stop the counter/timer module from running

This function starts or stops the counter timer module as a whole module. If the call specifies to stop, all counters and modules within the CTM will be "frozen." While stopped, you may still access all of the information and retrieve data from the various counters and check overflow flags, etc., but operation of the CTM is stopped.

Prototype:

void CTMRun (bool run);

Definition:

#include <cf1bios.h>

Inputs:

run indicates whether or not the CTM will be running after the function call returns.

Notes:

Timing:

Timing-TBD

CTMSetPrescale -- Set the clock sources and division ratios

This function configures the Prescaler(CPSM). The prescaler provides the clock to all the counters in the system. It has six clock outputs labeled PCLK1-6. The first 5 clock outputs are fixed (excepting the effect of the CPSMDivisor) fractions of the system clock. The sixth lines denominator must be selected by a P6DivisorID. Bear in mind that the highest frequency that any clock line will ever have is SYSCLK/2 because that is what is fed to the prescaler by a "pre-pre-scaler."(which incidentally is where the divide by 2 or divide by 3 operation takes place.) Refer to the following table:

Arguments

System clock/X on each clock line

CPSMDivisor

P6DivisorID

PCLK1

PCLK2

PCLK3

PCLK4

PCLK5

PCLK6

DivideBy2

P6Div32

2

4

8

16

32

64

DivideBy2

P6Div64

2

4

8

16

32

128

DivideBy2

P6Div128

2

4

8

16

32

256

DivideBy2

P6Div256

2

4

8

16

32

512

DivideBy3

P6Div32

3

6

12

24

48

96

DivideBy3

P6Div64

3

6

12

24

48

192

DivideBy3

P6Div128

3

6

12

24

48

384

DivideBy3

P6Div256

3

6

12

24

48

768

Prototype:

void CTMSetPrescale (CPSMDivisor div3, P6DivisorID p6select);

Definition:

#include <cf1bios.h>

Inputs:

div3 indicates whether the first prescaler should divide by two or by three. Valid CPSMDivisors: DivideBy2, DivideBy3
p6select chooses the subsequent divisor for PCLK6. Valid P6DivisorIDs: P6Div32, P6Div64, P6Div128, P6Div256

Notes:

At system startup, this function is called with the values DivideBy2, and P6Div64

Timing:

Timing-TBD

CTMTimeBaseReg -- Select time base bus and return pointer

This function returns a pointer a CTM register that, after this function call, contains the contents of the selected time base bus.

Prototype:

vushort *CTMTimeBaseReg(TimeBaseBusID timebase);

Definition:

#include <cf1bios.h>

Inputs:

timebase is the timebase you wish to read.

Returns:

A pointer to a register which mimics the contents of the selected time base bus.

Notes:

Valid TimeBaseBusIDs: TBB1, TBB2, TBB3, TBB4

Timing:

Timing-TBD

CTSAClearEventFlag -- Clear the counter event flag

Each Single Action Submodule that is set up to perform a given task will have an event flag to indicate whether the event it has been set up to perform has occurred. This function clears this flag to 0.

Prototype:

void CTSAClearEventFlag (SingleActionID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which Single Action Submodule whose event flag you wish to clear. Valid SingleActionIDs: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B

Notes:

Timing:

Timing-TBD

CTSADataReg -- Return pointer to counter's data register

This function returns a pointer to the register for the specified SASM. This register will be used by the SASM channel for input capturing, output comparing, etc. This is a read/write register and you my write into this pointer to load values for output capture and output capture toggle modes.

Prototype:

vushort *CTSADataReg (SingleActionID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASMs you want the register pointer from. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B

Returns:

Returns a pointer to the 16 bit data register for the specified SASM channel.

Notes:

Timing:

Timing-TBD

CTSAEdgeSelect -- Select the counter clock edge

This function is valid for input compare mode only. If it is in input compare mode, this chooses which edge on the input pin triggers the event.

Prototype:

void CTSAEdgeSelect (SingleActionID sm, bool pos);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASMs to set the trigger edge on. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B
pos is TRUE if you wish to capture on the rising edge or FALSE if you wish to capture the event on the falling edge.

Notes:

Timing:

Timing-TBD

CTSAFlipFlop -- Force the counter flip flop

This function sets the FORCE bit on the specified SASM channel. Setting the FORCE bit has several actions depending on mode. If the channel is in output compare mode, the FORCE bit makes the channel act as if the output compare event occurred. If it is in Output compare toggle mode, it forces a toggle of the output. In any other mode, writing the FORCE bit has no effect. Essentially setting the FORCE bit forces the output flip-flop to appear as if the event has occurred.

Prototype:

void CTSAFlipFlop (SingleActionID sm, bool force);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASMs to FORCE. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B
force is TRUE if you wish to set the force bit or FALSE if you wish to clear it.

Notes:

Timing:

Timing-TBD

 

CTSAGetEventFlag -- Return the counter event flag

Each Single Action Submodule that is set up to perform a given task will have an event flag to indicate whether the event it has been set up to perform has occurred. This function returns the current state of this flag.

Prototype:

bool CTSAGetEventFlag (SingleActionID sm);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which Single Action Submodule you wish to examine. Valid SingleActionIDs: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B

Returns:

Returns the current status of the event flag for the SASM in question

Notes:

Timing:

Timing-TBD

CTSAInterruptEnable -- Enable/disable counter interrupts

This function allows you to selectively enable and disable the interrupts on each channel of a dual channel SASM. See the reference for the CTSAInterruptLevel function for more information.

Prototype:

void CTSAInterruptEnable (SingleActionID sm, bool enable);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASMs to enable interrupts on. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B
enable is TRUE to enable interrupts and FALSE to disable interrupts.

Notes:

Timing:

Timing-TBD

CTSAInterruptFunction -- Insert the counter interrupt hander

This function installs an interrupt service routine for any interrupts generated by the specified dual channel SASM. This service routine should be a C function, taking no parameters and returning void, that was prototyped and declared with the IEV_C_PROTO and IEV_C_FUNCT macros discussed in detail in the Interrupt and Exception Vectors section of the reference manual. It can also be an assembly function.

Prototype:

void CTSAInterruptFunction (SingleActionID sm, vfptr *ifp);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASMs to set the interrupt service routine for. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B
ifp is either a pointer to an IEVCWrapper structure that is implicitly created by the IEV_C_FUNCT declaration macro or it is a function pointer to an assembly function.

Notes:

Timing:

Timing-TBD

CTSAInterruptLevel -- Set the counter IRQ and ARB levels

Each dual channel Single Action Submodule(SASM) is capable of generating an interrupt. If enabled, the SASM will generate an interrupt for either channel's event. This function allows you to specify the interrupt level upon which the interrupt will be generated if it is enabled. It also allows you to select one of two sublevels of interrupt arbitration. Each submodule of the CTM is capable of generating an interrupt on any interrupt request level. However, while 16 levels of interlevel arbitration are available on the intermodule bus, the CTM sets the low three bits of the arbitration number for the whole CTM in the Bus Interface Unit Submodule configuration register. Each other submodule can set the high bit of the arbitration "nibble" which essentially offers two possible arbitration numbers to each submodule in the CTM, one relatively high, and one relatively low. Also, while each channel of the dual channel SASMs can watch for a different event, they share all their interrupt levels and arbitration settings. This means that an event on either channel will trigger an interrupt of the same level and arbitration setting. This also means that if interrupts are spawned by both channels they will be executed in order of occurrence since no arbitration will occur between the two interrupts. You can selectively disable interrupts on a specific channel of the dual-channel SASM using the CTSAInterruptEnable function.

Prototype:

void CTSAInterruptLevel (SingleActionID sm, short il, short iarb3);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASMs to set the interrupt level of. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B
il is the systemwide interrupt request level at which the specified SASM's interrupt will execute
iarb3 represents the high bit of the interrupt arbitration number. (can be 0 or 1)

Notes:

Timing:

Timing-TBD

CTSAModeSelect -- Select the counter operating mode

Each channel of each single action submodule (SASM) can be configured for any one of four modes. The four available modes are Input compare, output compare, output compare toggle, and output port (simple I/O)

Prototype:

vushort *CTSAModeSelect (SingleActionID sm, SASMModeID mode);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASM channels to pick the mode for. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B
mode indicates which mode you wish to select for the given channel. Valid SASMModeIDs: SASMInCap, SASMOutPort, SASMOutCompare, SASMOutTogg

Returns:

A pointer to the selected SASM channel's status/interrupt/control register.

Notes:

Timing:

Timing-TBD

CTSATimeBaseBusSelect -- Select counters time base

This function selects which time base bus the single action submodule should be clocked from. Each dual channel SASM has access to only one pair of time buses and thus can only be driven by certain counters.

Prototype:

void CTSATimeBaseBusSelect (SingleActionID sm, bool busB);

Definition:

#include <cf1bios.h>

Inputs:

sm specifies which of the SASMs to enable interrupts on. Valid SingleActionID: SASM12A, SASM12B, SASM14A, SASM14B, SASM18A, SASM18B, SASM24A, SASM24B
busB is TRUE if the SASM should be clocked from bus B of the pair that it has access to. If it is FALSE it is driven from bus A of the pair it has access to.

Notes:

Timing:

Timing-TBD

 

Previous

Next

Top

Contents

Glossary

Index

Tel: 508-759-6434

Fax: 508-759-6436

Copyright (C) 1998 Persistor Instruments Inc. - All Rights Reserved