AN2573 Freescale Semiconductor / Motorola, AN2573 Datasheet - Page 8

no-image

AN2573

Manufacturer Part Number
AN2573
Description
LINkits LIN Evaluation Boards
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2573/D
Slave Software
8
The accompanying code listing for
First, the CONFIG, I/O, and timer registers are initialized. In the case of the
EY16, the ICG initial trimming value is also written to the ICGTR register. In the
demonstration application, this has been entered manually and the code
recompiled for each board; but in volume applications, this value could be
stored in FLASH and transferred to ICGTR at the start of code execution.
When all the required registers have been initialized, a while(1) loop is entered.
Execution of this loop is timed by the timebase module (TBM) on the GR60 and
EY16. Because the QY4 does not have a TBM module, it uses the main timer’s
overflow feature instead. Because of the different clocks used by each board,
the frequency of code execution in the loop is different for each slave type;
#defines are used to determine the two periods required for correct execution
of the program: push-button debounce time (about 60 ms) and mode change
time (3 s).
A third critical time (go to sleep in five seconds if there is no LIN activity) is
defined in slave.cfg (GR60 and EY16 only). This feature uses the LIN functions
LIN_IdleClock() and LIN_driverStatus() as described in the LIN driver manual
(see References). After the predetermined number of executions of
LIN_IdleClock(), with no LIN activity, LIN_driverStatus() ceases to return
LIN_OK (0x01), and the MC33399 is shut down by lowering its enable line. This
switches off the 5-V regulator and the MCU powers down.
If LIN messages are present, the remaining code in the loop is executed. This
increments count, toggles a port line (for debug use to check the loop execution
rate), reads the push-button switch using Read_button(), updates the LEDs
using LED_display(), and supplies the relevant response data using
LIN_response().
The flow chart for the function Read_button() is shown in
keycount is used to determine whether the push-button has been in a particular
state for long enough for action to be taken. It is used both for debounce and
to determine whether a mode change (normal to ID configuration or ID
configuration to normal) is required. If the state of the button (pressed or not
pressed) is different from what it was the previous time through the loop, the
counter is reset and the state remembered in key_last.
If, however, the state of the button is the same, the counter value is compared
with the required number for a debounce time of about 60 ms.
If the counter value is equal and the key is pressed, the data or ID is
incremented according to the current mode. If the count is different from that
required for debounce, it is compared with the mode change requirement.
Freescale Semiconductor, Inc.
For More Information On This Product,
LINkits LIN Evaluation Boards
Go to: www.freescale.com
Figure 3
is listed in back of this document.
Figure
4. The counter
MOTOROLA

Related parts for AN2573