+5VDC
+5VDC
U4
R7
10K
14
FWD/REV 7
ENABLE 8
BRAKE 1
MODE
PHASE
ENB
BRAKE
VCC 6
VLOAD 9
R8
10K
C6
680pF
R9
30K
2 REF
3 RC
13 GND
4 GND
5 GND
12 GND
A3953
VLOAD 16
OUTA 10
OUTB 15
SENSE 11
if(data[1] == mforward)
{
printf(“\r\nMOTOR FORWARD\r\n”);
mtr_fwd;
id = myid;
data[0] = nodeA;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
}
if(data[1] == mreverse)
{
printf(“\r\nMOTOR REVERSE\r\n”);
mtr_rev;
id = myid;
data[0] = nodeA;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
}
if(data[1] == mforwardbrk)
{
printf(“\r\nBREAK ON FORWARD\r\n”);
mtr_fwd_brk;
id = myid;
data[0] = nodeA;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
}
if(data[1] == mreversebrk)
{
printf(“\r\nBREAK ON REVERSE\r\n”);
mtr_rev_brk;
id = myid;
data[0] = nodeA;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
}
60 SERVO 09.2007
FIGURE 7. This is our
newly modified motor
driver menu that
communicates with our
CAN nodeA. Every trick
we turned with the LED
control was put to work
again in the CAN motor
driver code.
+5VDC
C7
.1uF
R10
1.00
+12VDC +12VDC
C8 C9
.1uF .1uF
SCHEMATIC 2
MOTOR
C10
.01uF
That does it for nodeB. Let’s turn our CAN coding
attention to nodeA.
For consistency, I’ve added the same motor driver
macros and motor drive CAN commands to the nodeA CAN
source code. The next thing we must do is modify the nodeA
CAN message status display messages. Before all we had
to report was the state of a single LED. We now have
four motor states we need to add to the status message task
list. No sweat:
if(data[0] == nodeA)
{
if(data[1] == led_off)
printf(“%c[10;5H NODE B REPORTS LED IS OFF“,esc);
if(data[1] == led_on)
printf(“%c[10;5H NODE B REPORTS LED IS ON“,esc);
if(data[1] == mforward)
printf(“%c[10;5H NODE B REPORTS MOTOR FORWARD“,esc);
if(data[1] == mreverse)
printf(“%c[10;5H NODE B REPORTS MOTOR REVERSE“,esc);
if(data[1] == mforwardbrk)
printf(“%c[10;5H NODE B REPORTS MOTOR BRAKE
FORWARD”,esc);
if(data[1] == mreversebrk)
printf(“%c[10;5H NODE B REPORTS MOTOR BRAKE
REVERSE”,esc);
}
We’ll never see those new status messages if we don’t
add some CAN commands to send to nodeB. It only takes a
bit of cut-and-paste work to put together the additional CAN
FIGURE 8. 0xA2 is the
command byte that repre-
sents “MOTOR FORWARD.”
Recall that we assigned
0xA2 to the motor
forward macro in
our CAN driver code.