Freescale Microcontroller programming

263 views 12 slides Dec 09, 2017
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

This report describes the control of an industrial oven using the Freescale semiconductor module. Starting with the functional specifications; then progressing to the description of the signals used, specifications and functions were needed for this task. Following the analysis of the code, analog t...


Slide Content

1





Faculty of Science, Engineering and Computing
School of Mechanical and Aerospace Engineering



Module: ME7731
Control Systems with Embedded Implementation

Coursework 1: Freescale
Microcontroller programming -
Microprocessor control of an
Industrial Oven

NAME: ATHANASIOS GALATAS
ID: K1639752
COURSE: MECHATRONIC SYSTEMS

NAME: SHIH CHENG TUNG
ID: K1617281
COURSE: AUTOMOTIVE ENGINEERING

2

Contents
Cover page: Freescale Microcontroller programming.......................................1
Table of figures………………………………………………………………………3
Abstract……………………………………………………………………………… 4
1. Introduction……………………………………………………………………….5
2. Brief description………………………………………………………………….5
3. Analysis…………………………………………………………………………...6
4. Debugging strategy……………………………………………………………
5. Flowchart…………………………………………………………………………
References………………………………………………………………………….
Appendix: Freescale Codewarrior Code ……………………………………

3




Table of figures

Figure 1. Freescale semiconductor (2016)…………………………………………….5
Figure 2. Freescale semiconductor connections “Control of an Industrial Oven”
(2016)……………………………………………………………………………………....9

4

Abstract

This report describes the control of an industrial oven using the Freescale
semiconductor module. Starting with the functional specifications; then
progressing to the description of the signals used, specifications and functions
were needed for this task. Following the analysis of the code, analog to digital
converter registers, functions were used as well as how the program works.
Connections for the ports of inputs, outputs and LED indications are described.
Lastly, a flowchart of the program is presented and debugging issues are
provided.

Key words: Freescale, signals, function, program, flowchart

5

1. Introduction

This task is about the control of an industrial oven. Our client is a sterilizing
medical equipment manufacturer, who wants to utilize this oven in temperatures
up to 250°C. For this project we will use the MC9S12C128 module with the
Freescale Axiom PBMCUSLK microcontroller (Figure 1). Our program will be
written in C language and after debugging the system will be simulated by using
the switch, pushbutton and two POTs of the board. This will help us to control the
current and required temperatures in order to test the program functions before it
will be used in the field.


Figure 1 Freescale Axiom PBMCUSLK microcontroller (2016)

6

2. Brief Description
We are going to use several inputs and outputs of the board to execute functions
properly. In particular, the signals which are going to be used are:

Function Signal
1. Start oven
2. Door closed
3. Door locked for temperatures over 100°C
4. Oven temperature set (POT)
5. Simulated temperature set (POT)
6. Oven ON/OFF indication (LED)
7. Door closed ON/OFF indication (LED)
8. Door locked ON/OFF indication (LED)
9. Heater ON/OFF indication (LED)
10. Temperature monitoring (LED)
11. Temperature out of range indication (LED)

This industrial oven will enter into operation by an ON/OFF switch and a LED
indication will show the operating mode. On of the potentiometer will adjust the
temperature up to 250°C and it will be monitored by 8 LEDs. Also, a potentiometer
will be used for the simulation of the temperature to test the oven. After closing the
door, the “door closed” indication LED will be switched on and when the
temperature reach 100°C the “door locked” indication will be switched on. If the
oven’s temperature overcomes the normal operation temperature (250°C) a
blinking LED alert will take place.
For the programming of the microcontroller we will use the “Codewarrior IDE” v5.2
software, C code language and USB port connect to the computer. All appropriate
wires will be connected to the module for the input and output signals. For the
temperature monitoring the onboard LED1 to LED8 will be used and displayed in
binary mode; the current and setting temperature will be adjusted from the two
onboard POTs (one on microcontroller and the other on the module) converting
the analog signal to digital with ATD converter. Also, three additional LEDs will be
used for the digital output signals.
In programming, before starting the analog to digital converter (ATD) for the POTs
function it is needed to declare its registers and specifications. After that, the
board’s outputs and inputs that will be used have to be declared. Then, functions
for the specific oven’s operation and temperature simulation will be written.
Furthermore, for the proper function of the code it is needed to compile and debug
for any errors, before final tests take place.
DI
DI
DI
AI
AI
DO
DO
DO
DO
DO
DO

7
















-













START
SW1
LED 1 ON
(Power
indication)
LED 1 OFF
(Power
indication)
POT 2
POT 1
PB1
LED 2 ON
(Door closed
indication)
LED 3 ON
(Door locked
indication)
POT 1 POT 2
LED 4 BLINK
(Warning
indication)
LED 4 OFF
(Warning
indication)
TEMP
MONITORING
OFF
TEMP
MONITORING
ON

LED 2 OFF
(Door closed
indication)
LED 3 OFF
(Door locked
indication)
>250
>250
>100
>100
OFF
ON
PUSH
RELEASE

8

Analysis

In the beginning of the code it is needed to declare the registers of the ATD. The
first register we declare is the ATDCTL2 to turn on the analog to digital converter;
the ADPU bit is used (Muhammad Ali Mazidi, Danny Causey, 2009, p. 444). So,
we have ADPU=1, AFFC=0 for normal flag clearing, AWAI=0 for the ATD to run in
wait mode. For the external trigger level and polarity we use falling edge sensitivity
(ETRIGLE:ETRIGP=00). The external trigger mode and the ATD sequence
complete interrupt are disabled (ETRIGE=0), (ASCIE=0). Lastly, there is no ATD
interrupt occurred (ASCIF=0). The register ATDCTL2 = 0b10000000 is declared.
The next register of the HCS12’s ATD declared is the ATDCTL3 which is used to
choose the amount of conversions per sequence. We choose “number of
conversions per sequence” (0010), because we want the ATD to convert the input
and place the results in ATDDR registers for the conversion of the POTs. Disabled
FIFO mode (0), FRZ1 and FRZ0 (00) continue conversion in freeze mode (break
point) is chosen (Muhammad Ali Mazidi, Danny Causey, 2009, p. 445). The
declaration for ATDCTL3 = 0b00010000.
The ATDCTL4 register will be used to select the conversion speed and the
resolution. Using the SRES8 bit 1 we select 8-bit resolution (Muhammad Ali
Mazidi, Danny Causey, 2009, p. 441). Then, using the SMP1:SMP0 we select the
sample time (00) for 2 A/D conversion clocks. For the A/D prescaler clock and bits
PRES4:PRES0 (0000) is selected as divisor value by 2. So, for the register
ATDCTL4 is declared ATDCTL4=0b10000000.
This program requires 12 outputs for the LEDs and 1 input. As we move on the
main function, HCS12’s inputs and outputs have to be declared. We setup PORTB
as output (DDRB =0xFF), PORTT bit-2-3-4 as outputs (DDRT = DDRT |
0b00011100) and PORTP bit-0 as output whilst PORTA bit-0 is declared as input
(DDRA &= 0x00). PORTB will be used for the temperature monitoring LEDs. Then
we initialize (turn off) the monitoring LEDs (PORTB), the start oven, close door
and alarm LEDs (PORTT) and the door locked over 100°C LED (PORTP). The
ATD converter initialization and the use of endless loop “for” are followed.
The register ATDCTL5 = 0b10110101 is declared to select the input analog
channel and start the conversion.
 DJM=1, Result register data right-justified
 DSGN=0, unsigned data representation
 SCAN=1, continuous conversion sequence
 MULT=1, sample across several channels
 CC CB CA=101, channel 5 (AN5) to start conversion

9

The conversion of the first potentiometer (on the microcontroller) will be stored in
variable ATDDR0L while the conversion of the second potentiometer (on the
Freescale board) will be stored in variable ATDDR1L.
Before start the conversion we have a function “if” for the main switch. Only if main
switch (PORTA_BIT0) is ON our program continuous to the next steps else it goes
to the end and do nothing turning off all LEDs.
When the oven starts (PORTA_BIT0 is ON) the temperature can be adjusted with
POTs and set the desired and the simulated temperature. The function for alarm
and warning temperatures greater or equal to 250°C follows. If registers ATDDR0L
and ATDDR1L are equal or greater than 250°C turn off all LEDs (PORTB, PORTP,
PORT_BIT3, PORTT_BIT4) and turn on and off the LED PORTT_BIT2 with
5000ms delay (blinking alarm).
For the temperature monitoring we use the onboard 8 LEDs which are connected
as outputs in PORTB. There can be monitoring the setting and the current
temperature and will show the smaller one. So, if POT1>POT2, 8 LEDs show the
result of POT2, else If POT2>POT1, 8 LEDs show the result of POT1. Door closed
and main switch indications LEDs remain ON.
Then the door locked function follows in which we want the door closed indication
to be ON after the 100°C. If the results in registers ATDDR0L and ATDDR1L are
greater than 100°C door locked indication in PORTP is ON, else if POT1 or POT2
are turned below 100°C door closed indication is off. Door closed and main switch
indications LEDs remain ON.

Freescale Semiconductor module connections

 PORTB (PB0-PB7) connected with onboard LEDs 1-8
 Switch ON/OFF SW1 as input in PA0
 Door locked external LED as output to PP0
 Switch ON/OFF LED as output to PT4 using a resistor for the LED
 Door closed indication LED as output to PT3
 Alarm indication LED to output PT2 using a resistor
 POT2 as input to PAD06
 One cable is connected to ground pin (GRD) to feed the breadboard
 A cable is connected from door closed LED to locked door LED for the
pushbutton PB1 to work for both

10

No resistors were used for the closed and door locked LEDs because the power of
the board was not enough to feed them and the pushbutton where are connected
has a resistor inside.
Connections and LED indicators are shown in the figure below.

Figure 2. Freescale semiconductor connections “Control of an Industrial Oven” (2016)

Debugging Strategy
Due to different outputs will be used in the programme, we have to explore other
ports of MC9S12C128. The format of other ports are slightly different, for example,
‘’PT’’ is been used instead of ‘’PORT’’. Thus ‘’PORTT_BIT0’’ caused an error in
the programme then that need to be replaced into ‘’PTT_PTT0’’.
‘’IF’’ instruction is essential part of the programme in order to approach the several
functions. The priority of conditions is one of the important requirements. The
function could be skipped with wrong order of instruction. For example, the LED
could be turn off when it supposed to be turn on. It is necessary to understand the
condition of every loops which are used.

11

12







250°


250°



100°



100°
START
POWER
LED 1 ON
PB1
LED 3 OFF
LED 3 ON
LED 2 ON
LED 2 OFF
LED 1 OFF
POT 1
POT 2
POT 2
LED 4 BLINK LED 4 OFF
Tags