Sie sind auf Seite 1von 10

Characteristics of PIC PWM controller measured by USB based

Data acquisition system


Yoshihiko Takase and George Ibrahim

Department of Mechatronics Engineering, Faculty of Mechanical and Electrical Engineering, Tishreen


University, Lattakia, Syria
Abstract
Practice project for students to learn the base of motor control by experiment and simulation was
planned. This was the first part of the project to prepare least necessary experimental setup to carry
out a series of precise experiments related to DC motor motion control. Hardwares of PIC16F88
Pulse-Width Modulation (PWM) controller, DC motor driver, data acquisition system using a
high-precision analog I/O terminal for USB 2.0 and software of the PIC PWM motor control were
prepared. Performance of the PIC16F88 PWM module was excellent for all of tested frequencies
up to 208.3 kHz. The analog I/O terminal (input resolution 16 bit and maximum conversion speed
10 µs) had sufficient performance to capture PWM and current dynamic signals. The present
performance test ensured that the experimental setup could be utilized to carry out PID control in
the next step.

1 Introduction
The combination of microprocessor and electric motor is one of the typical examples of mechatronics
and power electronics. The progress in power electronics has been possible primarily due to advances in
power semiconductor devices.[1],[2] The pulse-width modulation (PWM) technique also has long been
contributed to this advancement.[3],[4] The PWM signal generation depends on the chopper device and
controller. One of the popular microprocessors is the PIC[5] for control application. Most of PICs have
one or two Capture/Compare/PWM (CCP) modules inside. The popularization of microprocessor, PWM
technique, drive device, personal computer, and universal serial interface (USB) has brought desirable
benefits to students who studies the mechatronics engineering.
A project is planned which presents better understanding the mechatronics and power electronics
applications mainly for students in related fields. The project consists of: 1. Characteristics of PIC PWM
controller measured by USB based data acquisition system, 2. Basic simulation of digital standard-PID-
controller, 3. DC-motor speed control by PIC-based digital PID-controller, 4. DC-motor simulation and
verification of the result by experiment, 5. Locked anti-phase PWM PID-control of DC-motor speed, and
6. DC-motor position PID-control by simulation and experiment. This is the first part of the project.
The purpose of this study is to prepare minimum essentials of experimental setup to carry out a series
of precise experiments related to DC motor motion control. The study process is to prepare hardwares
of PWM controller with a PIC16F family, DC motor driver, data acquisition system by using a high-
precision analog I/O terminal for USB, to prepare software of the PIC PWM motor control, and to
examine the performance of the PIC PWM controller and the analog I/O terminal to capture dynamic
signals of the motor angular speed and current.

2 PIC PWM DC motor controller hardware


Hardware consists of PIC controller board, I/O board with motor driver, RS-232C terminal (popular
PC) and DC motor. The circuits of the PIC16F88 controller board, RS-232 to/from TTL USART, and

1
the I/O board with PWM DC motor driver are shown in Figures 1, 2 and 3, respectively. The I/O board
is equipped with mechanical switches, LEDs, transistor motor driver and n-p-n transistor H-bridge driver
IC (L298) to test various functions. In the present experiments the H-bridge was driven by the separate
direction and amplitude signals, often referred to as the sign/magnitude PWM,[6] as shown in Figure 3.
The peripheral features of the PIC16F88 are shown in Table 1.

Device Flash SRAM EEPROM I/O A/D CCP AUSART Comparators SSP Timers

(bytes) Pins (ch) (PWM) 8/16-bit

PIC16F88 7168 368 256 16 1 1 Y 2 Y 2/1

Table. 1 Peripheral features of the PIC16F88[7]

VDD
PIC16F88
VR 10kΩ
1 RA2 RA1 18

2 RA3 RA0 17
Timer 0 Counter Input I/O Connecter
3 RA4 RA7 16
T0CKI
R 100kΩ
4 MCLR 1 2 VDD VDD
RA6 15
IN0 OUT0 ADM232A
5 VSS 3 4
V DD 14
IN1 OUT1 C 0.1μ
5 6
6 RB0 RB7 13 1 C1+ Vcc 16
CCP1 PGD IN2 OUT2 C 0.1μ C 0.1μ
7 RB1 7 8 2 V+ GND 15
PGC 12
T1CKI IN3 OUT3 VSS
3 C1- T1out 14 RSout
8 RB2 9 10
RB5 11
RX TX GND Vcc 1 C2+ R1in 13 RSin
R 100kΩ 6 GND C 0.1μ
4
1 2
9 RB3 RB4 10 IN0 OUT0
RI 2 5 C2- R1out 12 TTLout
PGM Timer 1 7 DTR
3 4
C 0.1μ
Counter Input CTS 3 6 V- T1in 11 TTLin
IN1 OUT1
8 TxD
5 6
IN2 OUT2
RTS 4 RSout 7
T2out T2in 10 TTLin
9 RxD
7 8
IN3 OUT3
DSR 5 RSin 8
R2in R2out 9 TTLout
USART ISP CD
9 10
GND Vcc

1 2 1 2
I/O Connecter
TxD RxD PGM
3 4 3 4

5
RTS CTS
6 5
PGC
6
Fig. 2 Circuit of RS232C to/from TTL USART
PGD
7 8 7 8
Vpp
9 10 9 10
GND Vcc GND Vcc

Fig. 1 Circuit of PIC16F88 controller board

DC motor of a type of DME34SMA with magnetic revolution sensor, product of Japan servo Co., Ltd.
was used. Standard specification of the motor is that power supply is 12 V, output is 1.3 W and current
is 0.2 A.[8]
The experimental setup of PIC16F88 controller board, I/O board with motor driver and DC motor is
shown in Figure 4.

3 PWM controller program


To prepare software of the PIC PWM control the Capture/Compare/PWM (CCP) modules was tested
in two ways. The CCS C compiler was used to develop the program.

3.1 Duty-cycle control by analog signal


First, the PWM duty cycle was controlled by the DC voltage which was applied to the A/D converter
input, AN3 of the PIC16F88. This was a preliminary test to develop the next step of PID controller
which used feedback signal from the motor revolution sensor to control the duty cycle. The PWM control
program on CCP1 module by A/D analog input is shown below.[9]

2
R 51 kΩ x 4 74HC244 R 470 Ω x 4 Vs (12V)
LED3 LED2 LED1 LED0

BD201

1 2
IN0 OUT0 PG Output
3 4
IN1 OUT1 In 1 +Vs In 2
5 6 5 10 4 7 12
IN2 OUT2 Logic L298
7 8 Supply
IN3 OUT3 Voltage 9
9 10 3 OUT 2
GND Vcc 14

2 OUT 1
6 13
En A 11 1 15 8
PWM Signal SENSE A GND
R 10 kΩ x 4

Fig. 4 Photos of the experimental setup


Fig. 3 Circuit of I/O board with PWM DC motor driver

/**********************************************************************
* Filename: PWMPIC16F88a.c
* PWM control on CCP1 module by A/D analog input
* RA3: Analog input (0 - 5V), PWM output to RB0
***********************************************************************/
#include <16F88.h>
#fuses HS, NOBROWNOUT, NOWDT, NOPROTECT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2)

void main()
{
char selection;
byte value;

printf("\r\nFrequency:\r\n");
printf(" 1) 19.5\,kHz\r\n");
printf(" 2) 4.9\,kHz\r\n");
printf(" 3) 1.2\,kHz\r\n");

do {
selection = getc();
} while ((selection < ’1’) || (selection > ’3’));

setup_ccp1(CCP_PWM); // configure CCP1 as a PWM


set_tris_b(0xE4); // b’11100100’ PORTB<4,3,1,0> as output
// When the Timer1 oscillator is enabled (T1OSCEN is set),
// the RB6/PGC/T1OSO/T1CKI and RB7/PGD/T1OSI pins become inputs.
set_timer1(0);
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);

switch (selection) {
case ’1’: setup_timer_2(T2_DIV_BY_1, 255, 1); break;
case ’2’: setup_timer_2(T2_DIV_BY_4, 255, 1); break;
case ’3’: setup_timer_2(T2_DIV_BY_16, 255, 1); break;
}

3
setup_adc(adc_clock_internal);
set_adc_channel(3); // Pin2 for analog input (default analog)
output_low(PIN_B1);
output_high(PIN_B4);
printf("%c\r\n", selection);

while (TRUE) {
value = read_adc();
printf("%04X\r", value);
set_pwm1_duty(value);
}
}

3.2 Duty-cycle control by digital signal


Second, the PWM duty cycle was controlled by the mechanical switches which were connected to RA0
and RA1 of the PIC16F88. This was for the discrete control of the duty cycle in the present experiments.
The PWM control program on CCP1 module by digital input SW0-1 is shown below.

/**********************************************************************
* Filename: PWM16F88b.c
* PWM control on CCP1 module by digital input SW0-1, PWM output to RB0
* The ANSEL register and the ADCON1 register configure the functions
* of the port pins.
* ANSEL: ANALOG SELECT REGISTER PIC16F88 DEVICES ONLY
* Bits select input function on corresponding AN<6:0> pins.
* 1 = Analog I/O (default) 0 = Digital I/O
* b’11101000’: RA4, 2:0 are digital I/O
***********************************************************************/
#include <16F88.h>
#fuses HS, NOBROWNOUT,NOWDT, NOPROTECT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2)
#byte ANSEL = 0x9B // ANALOG SELECT REGISTER (ADDRESS 9Bh) PIC16F88 DEVICES ONLY

void main()
{
char selection;
byte value, initvalue, revolution;

printf("\r\nFrequency:\r\n");
printf(" 1) 19.5\,kHz\r\n");
printf(" 2) 4.9\,kHz\r\n");
printf(" 3) 1.2\,kHz\r\n");

do {
selection = getc();
} while ((selection < ’1’) || (selection > ’3’));

setup_ccp1(CCP_PWM); // configure CCP1 as a PWM


ANSEL = 0xE8; // b’11101000’: RA4, 2:0 are digital I/O (10/29)

4
set_tris_a(0xFF); // PORTA as input
set_tris_b(0xE4); // b’11100100’ PORTB<4,3,1,0> as output(6/13)

switch (selection) {
case ’1’: setup_timer_2(T2_DIV_BY_1, 255, 1); break;
case ’2’: setup_timer_2(T2_DIV_BY_4, 255, 1); break;
case ’3’: setup_timer_2(T2_DIV_BY_16, 255, 1); break;
}
output_low(PIN_B1);
output_high(PIN_B4);
printf("%c\r\n", selection);

initvalue = 0x3f;
while (TRUE) {
revolution = input(PIN_A2);
switch (revolution) {
case 0: output_low(PIN_B1); output_high(PIN_B4); break;
case 1: output_low(PIN_B4); output_high(PIN_B1); break;
}
switch (input_a() & 0x03) {
case 0: value = 0x3f; break;
case 1: value = 0x7f; break;
case 2: value = 0xbf; break;
case 3: value = 0xff; break;
}
printf("Revolution: %X SW: %04X\r", revolution, value);
set_pwm1_duty(value);
delay_ms(10);
}
}

4 Experimental
The PIC16F88 controller board is connected to PC through USB/RS-232C converter and to the I/O
board. The DC motor was connected to the motor driver output of the I/O board. The block diagram
and the photo of the experimental setup are shown in Figures 5 and 6, respectively.
The PWM signal was captured and stored to the PC by using a high-precision analog I/O terminal for
USB 2.0, AIO-160802AY-USB, product of CONTEC Co., Ltd. This product has bus-powered feature
for convenience and portability. It has analog input (16 bit, 8 ch), analog output (16 bit, 2 ch), digital
input (LVTTL×4), digital output (LVTTL×4). Some of the specifications are shown in Table 2.[10] The
analog I/O terminal comes with ”C-LOGGER”, a data logging software that provides graphic display,
saving to files and dynamic-export to Microsoft Excel. The PWM data was stored to PC in CSV format.
Graphs of voltage and current characteristics as a function of time were plotted by using the Excel.
On turning on the power of the experimental setup, a prompt to select PWM frequency (fP W M )
appears on the Hyper terminal. Frequency of fP W M = 1.2 kHz was selected.
The PWM wave forms at the duty cycles of 25, 50, 75 and 100 % are shown in Figures 7, 8, 9 and 10,
respectively.
Current flow of the motor was detected by the voltage drop across 0.5 Ω resistor which was connected
in series to the motor. The motor was under free running condition. The voltage drop was captured and
stored to the PC by using the analog I/O terminal described above. The current flow under the PWM
output with duty cycles of 25, 50, 75 and 100 % are shown in Figures 11, 12, 13 and 14, respectively.

5
PC with USB
Interfaces

A/D Converter
USB/RS-232 with USB
Converter Interface
Motor with
Rev. Sensor
PIC16F88 General Purpose
Controller I/O Board M PG
Board with Motor Driver

Power Supply Power Supply


(5 V) (12 V)

Fig. 5 Block diagram of the experimental setup Fig. 6 Photo of the experimental setup

Analog input Analog output


Input type Single-Ended Input Isolated specification Un-Isolated
Number of input channels 8ch Number of output channels 2ch
Input range Bipolar ±10 V Input Output range Bipolar ±10 V
Input impedance 1MΩ or moret Output impedance 1Ω or less
Resolution 16bit Resolution 16bit
Conversion speed 10 µsec (Max.) Conversion speed 10 µsec (Max.)
Conversion start trigger Software / external trigger Conversion start trigger Software / external trigger
Conversion stop trigger Number of sampling times / Conversion stop trigger Number of sampling times /
external trigger/software external trigger/software

Table. 2 Specifications of AIO-160802AY-USB [10]

PWM Output (Duty cycle = 25%) PWM Output (Dudy cycle = 50%)
6 6

5 5
Output voltage [V]
Output voltage [V]

4 4

3 3

2 2

1 1

0 0
0 500 1000 1500 2000 2500 0 500 1000 1500 2000 2500
Time [µs] Time [µs]

Fig. 7 PWM signal at duty cycle = 25 % and Fig. 8 PWM signal at duty cycle = 50 % and
fP W M = 1.2 kHz fP W M = 1.2 kHz

A performance of PIC16F88 CCP module was tested by setting fP W M to 1.2, 4.9, 19.5, 39.1, 78.1,
156.3 and 208.3 kHz. The PWM wave form at the highest frequency of 208.3 kHz was observed by using
an oscilloscope. The PWM output with duty cycles of 25, 50, 75 and 100 % are shown in Figures 15, 16,
17 and 18, respectively.

6
PWM Output (Duty cycle = 75%) PWM Output (Duty cycle = 100%)
6 6

5 5
Output voltage [V]

Output voltage [V]


4 4

3 3

2 2

1 1

0 0
0 500 1000 1500 2000 2500 0 500 1000 1500 2000 2500
Time [µs] Time [µs]

Fig. 9 PWM signal at duty cycle = 75 % and Fig. 10 PWM signal at duty cycle = 100 % and
fP W M = 1.2 kHz fP W M = 1.2 kHz

Current Flow of Motor (Duty cycle = 25%) Current Flow of Motor (Dudy cycle = 50%)
120 120

100 100

80
Current [mA]

80
Current [mA]

60 60

40 40

20 20

0 0
0 500 1000 1500 2000 2500 0 500 1000 1500 2000 2500
Time [µs] Time [µs]

Fig. 11 Current flow of motor (duty cycle = 25 % Fig. 12 Current flow of motor (duty cycle = 50 %
and fP W M = 1.2 kHz and fP W M = 1.2 kHz

Current Flow of Motor (Duty cycle = 75%) Current Flow of Motor (Duty cycle = 100%)
120 120

100 100

80 80
Current [mA]

Current [mA]

60 60

40 40

20 20

0 0
0 500 1000 1500 2000 2500 0 500 1000 1500 2000 2500
Time [µs] Time [µs]

Fig. 13 Current flow of motor (duty cycle = 75 % Fig. 14 Current flow of motor (duty cycle =
and fP W M = 1.2 kHz 100 % and fP W M = 1.2 kHz

7
Fig. 15 PWM signal at duty cycle = 25 % and Fig. 16 PWM signal at duty cycle = 50 % and
fP W M = 208.3 kHz fP W M = 208.3 kHz

Fig. 17 PWM signal at duty cycle = 75 % and Fig. 18 PWM signal at duty cycle = 100 % and
fP W M = 208.3 kHz fP W M = 208.3 kHz

5 Discussion
In the PWM mode, Timer2 rules a time base (period) and a time that the output stays high (duty cycle).
Timer2 is always counting up according to the clock, TOSC .
Two essential events which determine the PWM period and the PWM duty cycle occur when Timer2
matches PR2 and CCPR1H registers, respectively.
The PWM period can be calculated using the following formula.[5]

PWM Period = [(PR2) + 1] · 4 · TOSC · (TMR2 Prescale Value)

fP W M is defined as 1/[PWM period].

The following equation is used to calculate the PWM duty cycle in time.

PWM Duty Cycle = (CCPR1L:CCP1CON< 5 : 4 >) · TOSC · (TMR2 Prescale Value)

8
The maximum PWM resolution (bits) for a given fP W M is given by the following formula.
( )
log FFPOSC
WM
Resolution = bits.
log 2
In the present experiment, the following seven PWM frequencies were examined by using 20 MHz
oscillator.

(1/20000000) ∗ 4 ∗ 1 ∗ 24 = 4.8 µs or 208.3 kHz


(1/20000000) ∗ 4 ∗ 1 ∗ 32 = 6.4 µs or 156.3 kHz
(1/20000000) ∗ 4 ∗ 1 ∗ 64 = 12.8 µs or 78.1 kHz
(1/20000000) ∗ 4 ∗ 1 ∗ 128 = 25.6 µs or 39.1 kHz
(1/20000000) ∗ 4 ∗ 1 ∗ 256 = 51.2 µs or 19.5 kHz
(1/20000000) ∗ 4 ∗ 4 ∗ 256 = 204.8 µs or 4.9 kHz
(1/20000000) ∗ 4 ∗ 16 ∗ 256 = 819.2 µs or 1.2 kHz

In order to achieve higher resolution, fP W M must be decreased. In order to achieve higher fP W M , the
resolution must be decreased.
Table 3 lists example PWM frequencies and resolutions at FOSC = 20 MHz. The TMR2 prescaler and
PR2 values are also shown.

PWM Frequency [kHz] 1.22 4.88 19.53 78.12 156.3 208.3


Timer Prescaler(1, 4, 16) 16 4 1 1 1 1
PR2 Value 0xFF 0xFF 0xFF 0x3F 0x1F 0x17
Maximum Resolution (bits) 10 10 10 8 7 5.5
Table. 3 Example PWM frequencies and bit resolutions at FOSC = 20 MHz.

The performance of the CCP module in PWM mode of PIC16F88 is excellent for all of tested fre-
quencies. Even at the highest frequency of fP W M = 208.3 kHz the PWM wave form is almost ideal
rectangular pulse. For practical purpose, however, it may be necessary to set fP W M less than 20 kHz
because the resolution of PWM stays maximum value of 10 bit and there is a restriction of switching
time of the driver IC (typical commutation frequency of L298 is 25 kHz[11]).
The peak and bottom values of current in Figure 11 are about 120 and 20 mA, respectively. The
corresponding voltage drops across 0.5 Ω resistor are 60 and 10 mV, respectively. The high-precision
analog I/O terminal has the highest time resolution of 10 µs and voltage resolution of 16 bit. The
waveforms detected by the present data acquisition system, Figures 7 - 14, show that the analog I/O
terminal has sufficient performance to capture PWM signal delivered to the DC motor and current signal
through the motor of the order of 10 mV. The present performance test will ensure that the experimental
setup can be utilized to perform PID control in the next step.

6 Conclusion
Practice project for students to learn the base of motor control by experiment and simulation was
planned. This was the first part of the project to prepare least necessary experimental setup to carry out
a series of precise experiments related to DC motor motion control. Hardwares of PIC16F88 Pulse-Width
Modulation (PWM) controller, DC motor driver, data acquisition system using a high-precision analog
I/O terminal for USB 2.0 and software of the PIC PWM motor control were prepared. Performance
of the PIC16F88 PWM module was excellent for all of tested frequencies up to 208.3 kHz. The analog
I/O terminal (input resolution 16 bit and maximum conversion speed 10 µs) had sufficient performance to

9
capture PWM and current dynamic signals. The present performance test ensured that the experimental
setup could be utilized to carry out PID control in the next step.

References
[1] Bimal K. Bose: Power electronics and motor drives: advances and trends, Elsevier Inc.(2006).
[2] Singh and K. B. Khanchandani: Power Electronics, Tata McGraw-Hill Publishing Company Limited
(2007).
[3] William Shepherd, Lance Norman Hulley, and D. T. W. Liang: Power electronics and motor control,
Cambridge University Press (1995).
[4] Pushkin Kachroo, and Patricia Mellodge: Mobile robotic car design, The McGraw-Hill Companies,
Inc. (2005).
[5] Microchip Technology Incorporated: PICmicro Mid-Range MCU Family Reference Manual
DS31014A-page 14-8 (1997).
[6] National Semiconductor: LMD18200 data sheet, (1996), http://www.national.com/jpn/.
[7] Microchip Technology Incorporated: PIC16F87/88 Data Sheet DS30487C-page 1 (2005).
[8] JAPAN SERVO Co., Ltd.: Standard specification of DME34SA (2007), http://www.japanservo.
co.jp/digital/english/general/pdf/DME34 2.pdf.
[9] CCS: CCS C Compiler, refer to PICC\Examples\EX PWM.C.
[10] CONTEC Co., Ltd.: AIO-160802AY-USB Manual (Copyright 2006), http://www2.contec.co.jp/
prod data/aio160802ayusb/c01e.pdf.
[11] STMicroelectronics: L298 DUAL FULL-BRIDGE DRIVER data sheet (2000).

10

Das könnte Ihnen auch gefallen