Professional Documents
Culture Documents
(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
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.
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.
(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.
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.
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
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
Stop
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
NO
NO
YES
Stop
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
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
Is conversionType = Voltage?
NO
Is conversionType = Current?
NO
Is conversionType = Speed?
NO
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
YES
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
NO
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)
Differential calculation
YES
Sub or add?
Add
Subtract
YES
Limit to 0% speed
Limit to 100%
NO
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
YES
NO
End
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
Create the protocol Stack in following format [HEADER][COMMAND TYPE] [BYTE COUNT] [DATA BYTE 0][DATA BYTE N] [CRC][EOF INDICATOR]
End
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
NO
YES
NO Is PWM Counter > Duty Cycle count? Set PWM output pin to logic 0
Stop
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
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
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