You are on page 1of 15

International Journal of of Electrical and Electronics Engineering International Journal Electrical and Electronics Engineering Research and Development

(IJEEERD), ISSN 2248and Development (IJEEERD), ISSN 22481, Number 1, April-June (2011) Research 9282(Print), 2248 9290(Online), Volume

IJEEERD

9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011), pp. 18- 32 PRJ Publication http://www.prjpublication.com/IJEEERD.asp

PRJ PUBLICATION

DEVELOPMENT OF SCALABLE HARDWARE ABSTRACTION FRAMEWORK FOR DC MOTOR CONTROL APPLICATIONS


Ms. Puneet Kaur1, Dr.S.Chatterji2 Assistant Professor, Department of Electrical & Electronics Engineering, UIET, Panjab University, Chandigarh, India. E-mail: puneet2379@yahoo.com 2 Prof & Head, Department of Electrical Engineering, NITTTR, Chandigarh, India. E-mail: chatterjis@yahoo.com ABSTRACT
1

This paper discusses the development of ANSI C Application Layer Framework for dc motor controls. The author has a strong belief that the products involving the dc motor controls by utilizing this Application layer Framework can considerably reduce development time and effort. Software library discussed in this paper comprises almost all the functions required for dc motor control applications like SCR bridge firing angle control, current and voltage acquisition, speed measurement, PID control, digital filters, and communication protocol. It is scalable as per requirement, expandable, portable to any architecture and compatible with all micro OS / embedded kernels. Keywords Software Library for dc motor, SCR firing control subroutine, PID subroutines, data acquisition routines and digital filtering ,reusable Library functions, hardware abstraction. 1. INTRODUCTION Microcontroller market is showing trends towards high speed, low cost and more on-chip integration of peripherals. Semiconductor manufacturers are pushing the limits to match best possible features in microcontrollers due to which applications and products based on dc motor control can be accomplished with most of the available microcontroller families. On-chip peripherals like Timers, UART, PWM generators, Hardware interrupts, ADC etc, are found on most of the microcontroller architectures [1, 2]. This attribute accomplishes the requirement of cross platform application software library which in turn abstract the Hardware and can be easily ported and reused on different microcontroller architecture [3-5]. Keeping in view this concept, one such effort to create a platform independent ANSI C library has been discussed in this paper. Product revisions in industrial control applications usually include migration of the complete product to a different hardware and software platform. In such situations a developer can benefit from this software library and ensure a smooth transition to the new platform. Low resource usage and less processing requirements enhance its utility and also ease the integration efforts. Hardware can be reduced substantially by integrating motor control in the core applications rather then using a dedicated controller [6, 7] for this purpose. Also, architecture independence provides the developer a opportunity to make controller selection focusing on core applications. One such approach to create a software framework [8, 9] has been discussed in the present work. Following sections explain the details for each of the application layer modules.

18

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

2. SOFTWARE OVERVIEW As mentioned above, ANSI-C Application Layer Framework design has been discussed in the present article. The authors claim it to be independent of the microcontroller architecture as it is implemented only in the application layer. Library has the functions which are required for typical dc motor control applications, SCR firing control subroutine for example can be used to provide variable dc voltage to the motor. Speed measurement functions along with PID [10] sub routines can be used for the purpose of speed control. Data acquisition routines and digital filtering will assist in monitoring the current, voltage, motor temperature etc. Communication functions can similarly be used for the purpose of reporting the system parameters to the external world via UART. Salient features of the software are given below: Small footprint Low RAM and FLASH memory usage makes the library portable and easy to co exist with application code. Scalability Application software can use only the required modules out of the library which leads to optimal peripheral & memory usage. Expandability The Library can accommodate more modules and functionalities without affecting the existing ones. Some examples are H-Bridge control modules [11], Modbus over RS485 [12] etc. Portability The library is designed in the upper application layer, completely hiding the lower hardware layer. This abstraction of hardware makes the library Architecture and platform independent. Adaptability The library can be integrated with third party micro kernel / OS [13] to achieve desired functionality. Again, small resource usage enables it to be a good choice for low end microcontrollers also.

3. SOFTWARE DETAILS Table 1 gives the list of modules which have been developed in the software library along with their ANSI-C syntax [14] and the basic functions. However, the user can understand the working of each module with help of the various flowcharts provided for the different modules: S. No 1. Name of the module Zero Crossing Detector Interrupt Service Routine Module Timer Interrupt Service Routine for SCR Firing Pulse Generation Moving Average Filter Function of the module Detects the polarity and starting point of the sine wave and initializes firing angle to zero degrees. Generates the firing pulses for SCRs. ANSI-C syntax hwInterrupt_ZCD (void)

2.

tmrInterrupt_SCRfiring (void)

3.

Digital Filtering Subroutine for data acquired by ADC. It takes care of reducing white noise in the data. It accepts the data for filtering and returns the averaged output. It is a moving average algorithm for 16 points of data.

u16 movingAverageFltr (u16*samples)

19

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

4.

Data Conversion Module

(a) Accepts ADC data and returns value based on the conversion type parameter. It converts data to voltage, current, speed, temperature. (b) Generates the calibration coefficients for voltage, current, speed, temperature and accepts ADC data and returns voltage equivalent value for all.

u16 convertData (u8outputType, u16 sampleData)

5. 6.

PID Control Loop Module Speed Control PID Implementation Subroutine Communication Packet Creation Module Software Emulated PWM Module

7.

Accepts PID gain constants and implements the control loop Accepts the error and processes the variable for speed control and implements controls using PID loop Creates transmission packet for communication protocol

u16 Calibrate (u16 outputtype, u16 maxDataValue, u16minDataValue, u16 maxConvOutput, u16 minConvOutput, u16 offsetOutput) PID (u8 kp,u8 ki,u8 kd) u16 speedControl (u16 setSpeed, u16 actualSpeed) Createpacket (u8 *commData, u8 DestinationAddress, u8commType) tmrInterrupt_softwarePWM (void); Init_softPWM(u16 Freq, u16 DutyCycle)

8.

Initializes software PWM

Table 1 List of Modules developed in the software library

4. DETAILS OF THE VARIOUS MODULES Module 1 Zero crossing detector interrupt module Flow chart for this module is shown in Fig.1

20

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011) Start

Read ZCD output logic level

Is ZCD output =1

NO

YES

Select SCR pair to be fired in positive half of the input sine wave

Select SCR pair to be fired in negative half of the input sine wave

Initialize the value of firing angle to zero

Stop

Fig.1 Flow Chart for the Module 1 - hwInterrupt_ZCD (void)


This interrupt service routine will be implemented at the instant when the ac sine-wave (supply of the SCR bridge) will cross its zero level. Generation of the firing pulse train out of microcontroller, can be synchronized with input supply waveform (so that triggering of the SCR may be achieved at absolutely correct instant in every cycle of the supply by setting the Sine wave Angle counter to zero). By detecting the level of Zero crossing output (High or Low), the microcontroller will also derives the information for activating the pair SCRs corresponding to positive or negative half of the input ac wave-form.

Module 2 Timer Interrupt Service Routine for SCR firing pulse generation Flow chart for this module is shown in Fig.2

21

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Start

If Angle counter 180?

NO

If Angle counter > Firing angle?

NO

YES

YES Increment Angle counter Disable pulses for bridges

Disable pulses for bridges

Increment Angle counter

Stop

Fig.2 Flow Chart for Module 2 - tmrInterrupt_SCRfiring (void)


Legend for the flow chart in Fig 2 Description This variable is updated periodically and always keeps the value of current angle of the input sine-wave. Its maximum value is 180 degrees and minimum value is 0. Firing angle This is the value of sine-wave angle at which SCR pair should be triggered. Timer Interrupt service routine will keep track of the sine-wave angle (by incrementing Angle Counter variable) and will also compare it with the required value of firing angle. Whenever the value of firing angle becomes equal to the current angle of the input sine-wave, firing pulses will be applied to the SCRs. Variable Name Angle counter

22

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Module 3 Moving Average Filter module Flow chart for this module is shown in Fig.3

Fig.3 Flow Chart for Module 3 - u16 movingAverageFltr (u16*samples)


Legend for the flow chart in Fig 3 Variable Name Filter Buffer Description This is an array of 16 integer variables which is used as a first in first out buffer. With addition of every new sample in buffer, the oldest sample gets discarded. The working of filter buffer is depicted in figure 4. Value of this variable equals 16 which is the number of total samples in Filter Buffer.

Buffer length

Fig.4 Filter Buffer Moving average filter function will accept the input sample and will place it in the filter buffer, at the same time the oldest sample is discarded from the buffer. If the number of samples acquired equals the filter length, all samples are added and divided by filter length. The result will be returned to the calling subroutine.

23

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Module 4 Data conversion module Flow chart for this module is shown in Fig.5(i)
Start

Read SampleData and conversionType Variable

Is conversionType = Voltage?

NO

Is conversionType = Current?

NO

Is conversionType = Speed?

NO

Ifs conversionType = Temperature?

NO

YES
Multiply sampleData with Voltage multiplication coefficient and return results

YES
Multiply sampleData with current multiplication coefficient and return results

YES
Multiply sampleData with speed multiplication coefficient and return results

YES
Multiply sampleData with Temp. multiplication coefficient and return results

Stop

Fig .5(i) Flow Chart for Module 4 - u16 convertData (u8 conversionType, u16 sampleData)
Legend for the flow chart in Fig 5(i) Variable Name sampleData Description This variable is the ADC value ranging from 0-1023 (10-bits), which is to be converted to physical quantity i.e speed, voltage, current etc. This variable can have four different values corresponding to physical quantities like 0 - Voltage, 1- current, 2- speed, and 3temprature. Based on this value, convertData function will carry out the conversion to respective physical quantity.

conversionType

ConvertData function will accept the ADC count and will convert it as per specified by the conversionType variable. Data can be converted into voltage, current, speed, temperature. For conversion, the ADC count is multiplied by a conversion factor which is calculated by the calibrate function. Hence it is obvious that calibrate function must be executed at least once before implementing the convertData subroutine. Flow chart for calibration module is shown in Fig.5(ii)

24

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Fig .5(ii) Flow Chart for Module 4 - u16 Calibrate (u16 maxDataValue,u16 minDataValue, u16 maxADCoutput, u16 minADCoutput)

Legend for the flow chart in Fig 5(i) Variable Name maxDataValue Description This variable holds the maximum value of the physical parameter which can be achieved in the given system. E.g maximum voltage = 300VDC or maximum speed = 1500 rpm etc This variable holds the minimum value of the physical parameter which can be achieved in the given system. E.g minimum voltage = 0VDC or minimum speed = 0 rpm etc This variable is ADC value acquired corresponding to the maxDataValue variable on that channel This variable is ADC value acquired corresponding to the minDataValue variable on that channel

minDataValue

maxADCoutput minADCoutput

Calibrate function will accept minimum and maximum values of the ADC corresponding to minimum and maximum value of the parameter under calibration. After wards a multiplication factor is calculated assuming the linear behavior of the considered parameter and is stored in EEPROM memory of the microcontroller.

25

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Module 5 PID control module Flow chart for this module is shown in Fig.6
Start

A Subtract current speed from required speed


Sum to output value

Is Error < permissible threshold ?

YES

Terminate PID control

Get Error * Ki and add to integral accumulator

NO

Return Error * Kp
Is speed > 25% of max speed? YES Limit to 25% of max speed

YES Is speed > 75% of max speed? Limit to 75% of max speed NO

Sum to output value

NO

Integral Control A Proportional Control


Is sum >100% speed?
NO YES Limit to 100% of max speed

Differential Calculation

Continued-

26

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Calculate current error last error

Differential calculation

Is calculated error >50% max speed? NO

YES

Limit to 50% of max speed

Sub or add?
Add

Subtract

Subtract to output value

Add to output value

50% of max speed?


YES NO

YES

Limit to 0% speed

Is Sum>100% max speed?

Limit to 100%
NO

Load Timer/counters Differential Control Return

Fig .6 Flow Chart for Module 5 - PID(u8 kp,u8 ki,u8 kd)


Legend for the flow chart in Fig 6 Description Variable Name Kp Proportional gain multiplier Ki Integral gain multiplier Kd maxSpeed Differential gain multiplier Maximum value of speed of motor in the given setup

27

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Module 6 Speed control PID implementation subroutine Flow chart for this module is shown in Fig.7

Start

Calculate Error = Set Value Process variable

Is error within permissible limit?

YES

NO

Implement PID control

End

Fig .7 Flow Chart for Module 6 - u16 speedControl(u16setValue, u16 processVariable)


Legend for the flow chart in Fig 7 Variable Name setValue processVariable Description Desired speed of the motor Actual speed of the motor measured from transducer

Speed control function accepts the target speed variable and calls the PID function to achieve that value. The motor input voltage is the parameter manipulated by the PID function to achieve the constant speed. Actual speed is periodically acquired from speed transducer by utilizing the ADC.

28

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Module 7 Communication packet creation module Flow chart of this module is shown in Fig. 8

Start

Calculate CRC for communication data

Create the protocol Stack in following format [HEADER][COMMAND TYPE] [BYTE COUNT] [DATA BYTE 0][DATA BYTE N] [CRC][EOF INDICATOR]

Set Global Flag to indicate Comms packet ready for transfer

End

Fig .8 Flow Chart for Module 7 createpacket (u8 *commData, u8 DestinationAddress,u8commType)


Legend for the flow chart in Fig 8 Variable Name *commData commType Description Base address of the array containing data to be transferred. This variable indicate the type of data to be transferred, weather it is a control command or process data e.g ADC output or measured value of physical parameter.

Sub routine createPacket makes complete packet for faithful data transfer by encapsulating data with information like destination address, source address, byte count, Data type & CRC. CRC calculation algorithm may be a third party function which can be integrated in the application.

29

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Module 8 Software emulated PWM module Flow chart for this module is shown on Fig. 9(i)
Start

Read PWM Counter,Duty Cycle, maxPWM count variables

Increment PWM Counter

NO

Is PWM Counter > maxPWMcount ?

YES

NO Is PWM Counter > Duty Cycle count? Set PWM output pin to logic 0

YES Set PWM output pin to logic 1

Stop

Fig .9(i) Flow Chart Module 8 - tmrInterrupt_softwarePWM(void)


Legend for the flow chart in Fig 9(i) Variable Name PWMcounter Description This variable is incremented with each timer ISR execution and keeps track of the current position of the PWM waveform generated by microcontroller digital output pin This variable holds the value of maximum timer counts contained in one complete cycle of generated PWM waveform. This variable is derived from the PWM frequency and PWM resolution (dependent upon timer frequency). This variable holds the value of timer counts, after which the PWM waveform logic output should toggle in order to achieve desired duty cycle. This variable is modified by application level software to change the ON time OFF time ratio.

maxPWMcount

DutyCycleCount

30

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

Sub routine tmrInterrupt_softwarePWM function is placed inside the timer ISR and increment counts with each timer interrupt. Whenever the count become equal to the duty cycle of PWM, the output state of a digital output pin toggles its state and maintains that state unless the timer counts reach maximum value. The maximum count of timer interrupts within one cycle of PWM waveform defines the resolution of generated waveform. Flow chart for Initializing software emulated PWM module is shown on Fig. 9(ii)

Start

Read Input PWM frequency & Duty cycle

Calculate maximum timer counts per PWM waveform as shown below in formula (PWM frequency ) divide by (timer ISR frequency)

Calculate duty cycle counts by following formula (Duty Cycle/100) *( maximum timer counts)

Stop

Fig .9(ii) Flow Chart forModule 8 - Init_softPWM(u16 Freq,u16 DutyCycle)


Subroutine InitSoftPWM accepts the frequency and the duty cycle as inputs. The maximum frequency of the output PWM is limited by timer interrupt frequency and timer resolution. Higher the frequency of desired PWM waveform, lesser will be the resolution of control or PWM steps. 3. RESULTS & CONCLUSION The ANSI-C Library discussed in this paper has been successfully implemented on a MultiUtility-Device (MUD) which is a hardware platform designed by the authors for data acquisition, monitoring and control of dc motor [15]. The hardware is based on AVR microcontroller, with the provision of PC interfacing. The software integration has been incorporated using AVR GCC C compiler. Total memory and resource usage as shown below, supports the fact that library can be ported to any microcontroller and C-compiler smoothly: Flash Usage 16 kilobytes SRAM Usage 1.5 kilobytes

31

International Journal of Electrical and Electronics Engineering Research and Development (IJEEERD), ISSN 2248 9282(Print), 2248 9290(Online), Volume 1, Number 1, April-June (2011)

A universally executable code for each module has been developed by the authors finally. This code being flexible in nature, can be implemented on different hardware platforms supporting all microcontrollers. Sample platforms include MCS-51, AVR, PIC, AVR architecture etc. The library is an integration of modules required for typical electrical control application and has been developed to incorporate flexibility, expandability and also easy adaptability to users application. The details given for the software library can also help user to select optimal architecture and device for the end product. It is created keeping in mind both the generality and versatility and therefore can adjusted to specific needs. REFERENCES [1] ATMega 32 data-sheet. Atmel 2009.Available online http://www.atmel.com/dyn/resources/prod_documents/doc8155.pdf [2] PIC18 series microcontroller datasheet. Microchip 2006. Available online http://ww1.microchip.com/downloads/en/devicedoc/39564c.pdf [3] Cross platform application .USB Framework for PIC18, PIC 24 & PIC 32. Available online http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDo cName=en537044 [4] Cross platform application. Microchip Graphics library. Available online http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDo cName=en543091 [5] Cross platform application. TCP/IP Stack for PIC 18,PIC 24,dc PIC & PIC32. Available online http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&d DocName=en537041 [6] DC motor control card. SCR Bridge Firing modules. Available online http://www.libratherm.com/fl/p1.pdf [7] PC based data acquistion and control card, PCI -6208 series, by Amplicon. Available online http://instrumentation-central.com/SCRPowerControls/pci_series.pdf [8] P Dariusz Rzorica, Jan Sadolewski, and Bartosz Trybus, Prototype environment for controller programming in the IEC 61131-3 ST language, International journal published by ComSIS Consortium,Vol. 4, No.2, December 2007,pp 132-148. [9] Milan Vidakovi, Branko Milosavljevi, Zora Konjovi, and Goran Sladi, Extensible Java EE-Based Agent Framework and Its Application on Distributed Library Catalogues, International journal published by ComSIS Consortium, Vol. 6, No. 2, December 2009,pp 1-28. [10] PID controller/PID controller. Available online www.atmel.com/dyn/resources/prod_documents/doc2558.pdf [11] H-Bridge motor Driver. Available online http://www.atmel.com/dyn/resources/prod_documents/doc4856.pdf [12] Modbus protocol details. Available online www.modbus.org [13] Embedded operating systems. Available online www.FreeRTOS.org [14] Mullish Cooper, The Spirit of C, Jaico Publishing House. [15] Puneet Kaur, Dr S.Chatterji, Design and Development of a Multi-Utility-Device for data acquisition, monitoring and control, National Journal of Engineering & Technology Education, Vol 4, No 1,Jan-June 2010,pp31-37

32

You might also like