Sei sulla pagina 1di 5

Using PIC18F448 in wireless DC motor control

Abstract – Design of the drive circuitry of a DC motor A serial level converter (S.L.C.) is needed to match
using Microchip’s MRF24J40MA wireless module the voltage levels of the serial RS232 interface of the
combined with a PIC18F448 microcontroller and a host PC to the TTL logic levels of the PIC
MOSFET H-bridge. The wireless transmission is
microcontroller’s similar interface. A MAX232
achieved in the 2.4 Ghz frequency band and the above
mentioned microcontroller communicates with the MRF
circuitry will do the job. According to drive the MRF
module via SPI interface. wireless module, some control signals are needed to
Keywords: microcontroller, wireless, H-bridge be connected to the PIC18F448, stated as “Control” in
Fig.2., beside the usual SPI interface signals [1].
I. INTRODUCTION The receiving unit (R.U.) contains a similar MRF
module and a PIC18F448 microcontroller which not
A host computer will generate command words to only controls the wireless module but stores the DC
drive the DC motor which are decrypted at reception motor control data sent by the host PC, decrypts the
by the PIC microcontroller. Thus one can implement values for spin direction and speed, drives the
actuation based upon a predefined command table MOSFET H-bridge and processes the feedback
stored locally in the PIC’s Data EEPROM. The signals from the DC motor. Fig.3. depicts the bloc
transmission is achieved using a PIC18F448 diagram of the receiving unit combined with the
communicating with the host PC via RS232 serial motor driving circuitry.
interface and connected to the MRF24J40MA
wireless module provided by Microchip. Reception is RF PWM x4
SPI
implemented with a similar MRF24J40MA module Gate drivers
connected to a PIC18F448 microcontroller using the MRF PIC
SPI interface. Also this unit drives a full MOSFET H- 18F448 Current Feedback Vc
bridge suited for a DC motor control thus c
Contr
implementing a forward or reverse mode. ol H-Bridge

R
II. SYSTEM OVERWIEV DC Motor

Basically, the entire device can be illustrated as it is


Mechanical Feedback
shown in Fig.1.
Fig.3. Receiving and driving unit
RS23
Host 2 T.U. Wireless RF
PC Signals from the four PWM outputs are forwarded to
the MOSFET H-bridge through adequate gate drivers.
Wireless RF We will use TC428 dual high-speed power MOSFET
drivers [2].
R.U. H M The driving algorithm can use a current feedback to
Bridge regulate the motor torque and a mechanical feedback
to control speed or position. These feedbacks are
optional.
Feedback

Fig.1. System diagram III. DEVICE INTERFACING

Fig.2. indicates a detailed bloc diagram of the The PIC18F448 communicates with the MRF wireless
transmission unit (T.U.). module as it is shown in Fig.4.
RS23
2 S.L.C.

RF
SPI

PIC MRF
18F448

Contr
ol
Fig.2. Transmission unit diagram Fig.4. Connecting PIC18F448 with the MRF24J40MA
The MRF24J40MA module operates in the 2.4 GHz voltage, power management applications [4].
frequency band and is FCC, IC and ETSI compliant. ZXMHC6A07T8 is a complementary 60V
The integrated module design allows quick and enhancement mode MOSFET H-bridge with low gate
simple usage without any supplementary regulatory drive, suitable for this application. Fig.6. gives the
compliance test, thus allowing quicker product circuit configuration and Fig.7. the pinout diagram.
development and time to market [1]. The module
interfaces to the PIC18F448 via 3-wire serial SPI,
using Serial interface data input (SDI), Serial interface
data output (SDO) and Serial interface clock (SCK).
In addition a serial interface enable pin is used (/CS),
connected to a usual I/O line. Furthermore, interrupt,
wake and Reset signals are required to fully operate
the module. Excepting the interrupt, all other lines are
driven by usual I/O microcontroller pins. Table 1
indicates the pin assignment to the MRF and
PIC18F448 interfacing.
Fig.6. ZXMHC6A07T8 configuration
Table 1
PIC RB0 RB1 RB2 RB3 RC3 RC4 RC5
MRF INT /CS Wake / SCK SDI SDO
Reset

In order to command the MOSFET H-bridge, we will


use the built in DC motor control options of the PIC’s
ECCP module (Enhanced Capture/Compare Module)
to provide a simple and efficient driving method.
P1A, P1B, P1C and P1D are the outputs from the
ECCP module (lines RD4 – RD7) and they are Fig.7. ZXMHC6A07T8 pinout diagram
configured as Full Bridge mode (Forward or Reverse)
[2]. Actually, lines RD4 – RD7 are directly connected To implement a bidirectional DC motor control, a
to the inputs of four gate drivers to assure level classic H-bridge wiring configuration is used in
compatibility and proper current drain from the port addition with a current feedback actually proportional
lines. Two TC428 integrated drivers with with the voltage on the resistor R as depicted in Fig.8.
complementary outputs are used as shown in Fig.5. A
TTL/CMOS input voltage level is translated into a PIC18F448
rail-to-rail output voltage level swing. The CMOS
output is within 25 mV of ground or positive supply RA1 P1A P1B P1C P1D
[3].
TC428 InA InB InA InB

(RD4)P1A InA /OutA nMOS TC428 TC428


/OutA OutB /OutA OutB

(RD5)P1B InB OutB pMOS

G1 G2 G4
G3 ZXMHC6A07T8
TC428
(RD6)P1C InA /OutA nMOS S2,S3 S1,S4 D1,D2 D3,D4

(RD7)P1D InB OutB pMOS


M
PIC8F448 R Vcc
Fig.5. Interfacing PIC18F448 to the H-bridge

According to Fig.5. all PWM outputs are active high Fig.8. H-bridge interfacing
thus turning on the respective MOSFET due to
complementary outputs of TC428. Input logic signals Pin RA1 of PIC18F448 is used as an analog input and
may equal the power supply voltage and the input should be configured accordingly. Optional
current is 1mA, making direct interface to CMOS mechanical feedback can be added to the system using
microcontrollers simple and easy [3]. The H-bridge pins RA2, RA3 and RA4 set as digital inputs
used hereby is a new generation of MOSFETs from depending on the chosen transducer (i.e. incremental).
Zetex, utilizing a unique structure that combines the Any DC motor up to 60V/1A can be used due to the
benefits of low on-resistance with fast switching integrated ZXMHC6A07T8 H-bridge. According to
speed, making them ideal for high efficiency, low
the used DC motor the R resistor must be turns to 1 indicates that SSPBUF has been loaded
dimensioned properly regarding power dissipation. with the received data (transmission completed).
IV. SOFTWARE CONFIGURATION When the SSPBUF is read, the BF bit is cleared
which is relevant only when the SPI is a receiver
System operation starts when the host PC is sending 8 (used for the receiving unit).
bit command words to the transmission unit (T.U.) via
the RS232 serial interface. Therefore, the T.U.’s
PIC18F448 USART (Universal Synchronous
Asynchronous Receiver Transmitter) is used in
synchronous slave reception. Pin RC6 is assigned for
the serial clock and pin RC7 for the receive Rx signal.
The following steps should be achieved in software
initialization:
-setting the bits SYNC, SPEN;
-clearing the bit CSRC from the TXSTA register;
-clearing the bits CREN, SREN;
-enabling USART interrupts by setting the bit RCIE
from the PIE1 register.
Testing if the USART Receive Interrupt Flag bit,
RCIF is set, will show the end of transmission [5].
Then an interrupt request is generated and a propper
subroutine will read the value from RCREG which
gives the wanted command word. Each received word Fig.9. SPI Master mode waveforms
is stored afterwards in the data memory of the Before operating with the MRF24J40MA, the init
receiving unit. Table 2 shows the layout used for the routine should perform a high level setting on /CS (by
command word. setting the RB1 pin) and also the same for the
/RESET (RB3 pin). SPI setup routines must be run on
Table 2 both microcontrollers (on transmission and receiving
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Direction Speed in % of the maximum rpm of the motor units) to initialize the respective wireless modules.
Initializing the MRF24J40MA means to issue a
“Direction” can be “0” for clockwise and “1” for sequence of auxiliary operations like setting the
counterclockwise and speed a value between 0 – transmission channel and enabling or disabling the
100%, encoded binary on 7 bits. The sequence interrupts. Also, on start-up, certain control register
10001111 means a counterclockwise rotation with values must be initialized for basic operations [1].
15% of the maximum motor speed. First initialization steps are shown as follows.
In order to operate the MRF24J40MA, the MSSP 1. SOFTRST (0x2A) = 0x07 – Perform a software Reset;
(Master Synchronous Serial Port) module of the 2. PACON2 (0x18) = 0x98 – Initialize FIFOEN = 1 and
PIC18F448 must be initialized and entered in SPI TXONTS = 0x6;
(Serial Peripheral Interface) communication mode. 3. TXSTBL (0x2E) = 0x95 – Initialize RFSTBL = 0x9;
Pins RC3, RC4 and RC5 are used for the SPI. Also 4. RFCON1 (0x201) = 0x01 – Initialize VCOOPT = 0x01;
5. RFCON2 (0x202) = 0x80 – Enable PLL (PLLEN = 1);
RB0, RB1, RB2 and RB3 control the MRF, according
6. RFCON6 (0x206) = 0x90 – Initialize TXFIL = 1 and
to Table 1. Therefore PIC’s TRISB register should be 20MRECVR = 1;
loaded with the hexadecimal value 0x01 and TRISC 7. RFCON7 (0x207) = 0x80 – Initialize SLPCLKSEL = 0x2
with 0xD0. To write or read data with the MRF, SPI 8. RFCON8 (0x208) = 0x10 – Initialize RFVCO = 1;
mode 0 must be used. The maximum SPI clock 9. SLPCON1 (0x220) = 0x21 – Initialize CLKOUTEN = 1
frequency must not exceed 10 MHz. Therefore if we and SLPCLKDIV = 0x01;
use a 20 MHz oscillator as clock for the PIC18F448, a 10. BBREG2 (0x3A) = 0x80 – Set CCA mode to ED;
software division with 4 is required. To enable the 11. RSSITHCCA (0x3F) = 0x60 – Set CCA ED threshold;
port, SSPEN bit from SSPCON1 register must be set. 12. BBREG6 (0x3E) = 0x40 – Set appended RSSI value to
RXFIFO.
This configures the SDI, SDO, SCK, and SS pins as
serial port pins [2]. Next, bits SSPM<3:0> must be The next step (13) is to enable interrupts, on pin INT
cleared (in SSPCON1 register) to achieve a division of the MRF24J40MA to signal the microcontroller
by 4 of the Fosc (20 MHz). The clock polarity must when a successful transmission or reception have
be selected by programming the CKP bit from been made. Interrupts are enabled via the INTCON
SSPCON1, the CKE (Clock Edge) and SMP (Sample) register (0x32) and the INTSTAT (0x31) indicates the
from SSPSTAT register according to SPI waveforms status of operation and it is automatically cleared
illustrated in Fig.9. That means, for SPI mode 0 CKP when read. Thus, the INT pin will continue to signal
and CKE will be cleared and the SMP set. When an interrupt until the INSTAT register is read. Also
receiving data, bit BF (Buffer Full) from SSPSTAT the edge polarity of the INT pin should be configured
should be flagged. If 0 it means empty and only if it accordingly to the interrupt input of the PIC18F448.
In our case we choose interrupt on falling edge this where tvalue is the word issued by the host PC and to
being the default on the MRF module after RESET. be transmitted to the receiving unit via the MRF.
That means INTEDG0 will be cleared in the Based upon the transmitted command word, the
INTCON2 register of the PIC18F448 microcontroller. PIC18F448 from the receiving unit generates four
PWM signals using the built in ECCP module. The
A channel selection follows (14). The MRF24J40MA
PWM period is specified by writing in PR2 register.
is capable of selecting one of sixteen channel
The value to be written is given by:
frequencies in the 2.4 GHz band [5], listed in Table 3.
PWM period = [(PR2) + 1] • 4 • TOSC • (TMR2 p.v.) (1)
Table 3
where TMR2 p.v. is the prescale value set by TMR2
and Tosc is the period of the clock oscillator
according to a 20 MHz frequency that is used. The
PWM duty cycle is calculated using:
PWM duty cycle = (ECCPR1L:ECCP1CON<5:4>) •
TOSC • (TMR2 p.v.) (2)

The ECCPR1L contains the eight MSbs and the


ECCP1CON<5:4> contains the two LSbs thus making
a 10 bit wide word. The EPWM1M<1:0> bits in the
ECCP1CON register allows to switch the ECCP
operation between Full – bridge output forward or
reverse mode. In order to use the ECCP, bits
TRISD<7:4> should be cleared thus making pins
RD7:4 outputs. Table 4 shows the operating modes.
Table 4
MODE ECCP1CON
Forward ‘b01xx1100’
Reverse ‘b11xx1100’
In order to use the current feedback on pin RA1 we
Bits RFCON0<7:4> (address 0x200) select the use a initializing routine of PORTA as follows:
desired channel. The current application will use
channel 11. After channel selection we perform as void analog_init()
follows: {
15. RFCTL (0x36) = 0x04 – Reset RF state machine; PORTA=0;
16. RFCTL (0x36) = 0x00; LATA=0;
17. Delay at least 192 μs. ADCON1=0x80;
Step 17 is necessary to allow the RF circuitry to TRISA=0xFF;
recalibrate after the RF State Machine Reset [5]. }
A simple function to receive a word from the MRF When acquiring an analog value, the integrated A/D
module via SPI interface, after it is set in receiving
converter is used and the conversion is started by
mode is written bellow: setting bits ADON and GO/Done of ADCON0
void receive(int rvalue) register.
{
while (!SSPSTAT.F0)
{} V. REMARKS
rvalue=SSPBUF;
} Combining known DC motor driving methods with
new concepts regarding wireless communication this
where rvalue will be loaded with the SSPBUF value
approach is intended to offer support to further
after a successful wireless transmission. When development of automation devices. Focused mainly
transmitting a value a simple routine should be used,
on achieving the wireless communication the
like the following: proposed method can be used to implement a complex
void transmit(int tvalue) wireless robotic drive system.
{
SSPBUF=tvalue; REFERENCES
}
[1] Microchip Technology Inc., “MRF24J40MA Datasheet”, 2008
[2] Microchip Technology Inc., “PIC Microcontroller CCP and
ECCP Tips’n Tricks”, 2008
[3] Telcom Semiconductor Inc., “TC428 1.5A dual high-speed
power MOSFET drivers”1996
[4] Zetex Semiconductors, “ZXMHC6A07T8 complementary 60V
enhancement mode MOSFET H-bridge Datasheet”, 2005
[5] Microchip Technology Inc., “PIC18F448 Datasheet”, 2001

Potrebbero piacerti anche