Minimize communication time between small microcontrollers

Abel Raynus, Armatron International Inc, Melrose, MA -- EDN, 3/29/2001

When designing a multicontroller system, it is convenient to organize the communication between µCs via one wire line. Unfortunately, low-end µCs have no serial-interface capabilities like their more expensive counterparts. Low-end µCs have no SCI (serial-communication-interface, SPI (serial-peripheral interface), or SIOP (simple serial-I/O port). Thus, a designer needs to use software tools to create a serial interface (Reference 1). One approach, which uses the external interrupt for message receiving, results in message duration of 13.5 to 21.5 msec. For many applications, this time is unimportant. However, some applications may require you to minimize the message time as much as possible, especially when both the timer and external interrupts are in use. The µC cannot simultaneously execute these interrupt requests, and the external interrupt has a priority. Hence, a message and, therefore, the external-interrupt-service routine that are too long can affect the program-process timing related to timer interrupt.

You cannot minimize the message time by just changing some number in the program. You must instead use a time-measurement concept that leads to modification of the whole program (Figure 1). The data word from one µC to another comes to Pin pA0, which you program as an external-interrupt input. When an external interrupt occurs, the µC can process this interrupt only when the current instruction execution is complete. This waiting time is always unpredictable and can range from zero to the time of the longest instruction in the program (Figure 2). So, this time differs for each user program. Nevertheless, if a program has no exotic instructions, such as SWI (software interrupt) and MUL (multiplication), then the longest instruction can execute in six cycles, which takes 3 µsec for an oscillation frequency of 4 MHz (Reference 2). Saving the contents of the CPU registers on the stack and loading the program counter with an external-interrupt vector address take nine more cycles.

Only at this point can the interrupt-service routine begin the pulse-width measurement. (Click here to download the message receiver and transmitter programs.) After executing three instructions (lines 36 to 38 of the message-receiver program), this process completes in 12 cycles, or 6 µsec. Hence, the width of an external interrupt pulse cannot be less than 10.5 µsec.

From another side, it is more convenient for the transmitter part of the program to use only one subroutine, called Pulse, to generate all the pulses with different widths by changing the number of the loop repetitions (X) only. The loop duration is 5 µsec (lines 43 to 46 of the message-receiver program), so the generated pulse is equal to 5X+2.5 µsec. You can choose the pulse-width values according to your project objectives. In this case, for LOG0 X=2, width=12.5 µsec; for START X=4, width=22.5 µsec; and for LOG1 X=6, width=32.5 µsec. However, as you can see from Figure 2, the pulses that the receiver measures are shorter by 4.5 µsec than transmitted pulses. So, the measured pulses have widths of 8, 18, and 28 µsec. The µC's internal free-running timer/counter is the clock. You can at any time read the value of the first eight stages of this counter from the (TCR) time-counter register. One time count is equal to four machine cycles, or 2 µsec. Note that the pulse-width measurement must be complete before the TCR overflow that happens every 2×256, or 512 µsec. In the program, the unit of pulse-width value calculated and put into register pW is one timer count (clk). So the widths of LOG0, START, and LOG1 pulses are 4, 9, and 14 clk, respectively. Remember that the moment of beginning and external interrupt processing could be at any time in the range of 3 µsec, or 2 clk, which causes the same variations in the measured pulse width. To overcome this problem, you select the proper pulse width within a fork, which should greater than or equal to 2 clk. In this case, the fork is equal to 4 clk. Finally, you use the following pulse selection logic: 3 clk

The minimal interval between the two consecutive external-interrupt pulses should be more than the number of interrupt-service-routine cycles plus 19 cycles (Reference 2). The service routine's longest path occurs when the program is processing the widest incoming pulse (LOG1), which takes 47 cycles. Thus, the interval between pulses should be more than 47+19=66 cycles, or 33 µsec. Choosing the number of time-loop repetitions of X=10 results in a 52.5-µsec pause between pulses (lines 48 to 52 of the message-receiver program). With all the above chosen values, the longest message, $ffHEX. lasts 0.84 msec.

The design in Figure 1 uses a one-time-programmable Motorola MC68C705JK1 (Motorola µC, but this idea is applicable to any µC. You would need to recalculate the timed values according to the µC's technical data.

References
Raynus, Abel, "Single wire connects microcontrollers," EDN, Oct 22, 1998, pg 102.

MC68HC705KJ1/DTechnical Data, Revision 1.0, Motorola.




ADVERTISEMENT

ADVERTISEMENT

Feedback Loop


Post a CommentPost a Comment

There are no comments posted for this article.

Related Content

 

By This Author


ADVERTISEMENT

Knowledge Center



Technology Quick Links

EDN Marketplace


©1997-2008 Reed Business Information, a division of Reed Elsevier Inc. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other Reed Business sites