EDM18B010 - Expt4-Embedded System Design Practice
EDM18B010 - Expt4-Embedded System Design Practice
Aim:
In this experiment we will deal with passing a sequence of control signals with
specific time intervals to control the stepper motor using SysTick timer.
Requirements:
● PC running on windows
● Keil uVision
● TivaWare
● Stellaris ICDI drivers
Theory:
Systick timer is a dedicated hardware-based timer which is built inside the ARM Cortex M4
CPU and can be used to generate an interrupt at a fixed interval of time. As shown in the
figure below:
The systick timer will generate interrupts after a specified time and time settings can be done
using the Systick control register.
This figure given below depicts the working behavior of a systick timer of ARM cortex M4
microcontroller:
As you know that the system timer of TM4C123G microcontroller is a 24-bit down counter.
We reload the initial value to reload register and counter decrements from reload value to
zero. The value of the counter decrements on every positive edge of the clock cycle. When
counter values reach zero, the system timer generates an interrupt. Also, the counter is
re-initialized with a reload value again. Hence, the process keeps repeating.
Procedure:
To initialize an I/O port for general use:
1. Activate the clock for the port in the Run Mode Clock Gating Control Register 2 (RCGC2).
PortF=0x00000020; PortB=0x00000002; PortA=0x00000001
Use “selective high” i.e “|=” to initialize the clocks for ports whenever using multiple
ports as the variable SYSCTRL_ RCGC2 is common for all.
2. Unlock the port (LOCK = 0x4C4F434B).
GPIO_PORTF_LOCK_R = 0x4C4F434B; (Default)
3. Disable the analog function of the pin in the Analog Mode Select register (AMSEL), because
we want to use the pin for digital I/O. If this pin is connected to the ADC or analog
comparator, its corresponding bit in AMSEL must be set as 1. In our case, this pin is used as
digital I/O, so its corresponding bit must be set as 0.
GPIO_PORTF_AMSEL_R = 0x00;
4. Clear bits in the port control register (PCTL) to select regular digital functions. Each GPIO
pin needs four bits in its corresponding PCTL register. Not every pin can be configured to
every alternative function.
GPIO_PORTF_PCTL_R = 0x00000000;
5. Set its direction register (DIR)-i.e whether the port is output or input. A DIR bit of 0 means
input, and 1 means output.
GPIO_PORTF_DIR_R = 0x0E; (00001110)(PF 1-3 input, PF0 & PF4 output)
6. Clear bits in the alternate Function Select register (AFSEL).
GPIO_PORTF_AFSEL_R = 0x00;
7. Enable digital port in the Digital Enable register (DEN).
GPIO_PORTF_DEN_R = 0x1F; (00011111)(Enable PF0 to PF4 registers)
Systick Timer:
Reload period:
This is a picture of a stepper motor run in a full step mode. Here 2 coils are active at
any given time providing better torque
Formula:
o
360
S tep angle = Steps per Revolution
S teps per revolution = no. of teeth * no. of poles
Here, the number of teeth is 100 and the motor is a bipolar motor.
Therefore the step angle comes out to be 1.8o
Code:
Example exercise: Move the stepper @ portD by 90o(T=10ms)
#include "PLL.h"
#include "tm4c123gh6pm.h"
#include <stdint.h>
int main(void){
unsigned long int i=0,k;
PLL_Init();
SysFun();
Port_Init();
SysInit();
while(1){
for (i=1; i<13;i=i+1)
{
GPIO_PORTD_DATA_R=0x05;
SysLoad(800000);
GPIO_PORTD_DATA_R=0x06;
SysLoad(800000);
GPIO_PORTD_DATA_R=0x0A;
SysLoad(800000);
GPIO_PORTD_DATA_R=0x09;
SysLoad(800000);
}
GPIO_PORTD_DATA_R=0x05;
SysLoad(800000);
GPIO_PORTD_DATA_R=0x06;
SysLoad(800000);
}
}
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0;//any write to current clears it
NVIC_SYS_PRI3_R=NVIC_SYS_PRI3_R&0x00FFFFFF;//priority 0
NVIC_ST_CTRL_R=0x00000005; //ENABLE WITH CORE CLOCK AND INTERRUPTS
}
void SysFun(void){
}
Output: port D 0° to 90 °
0° to 90 ° - Continuously giving pulses of 10ms length in a specific sequence(5->6->a->9) so
as to make the motor move in clockwise direction. Repeat this sequence for 13 times to get
90o of step angle.
5 -> 6 -> a -> 9 sequence can be observed. This pattern repeats for 13 times in order to turn 90o
Code:
Exercise: turn the stepper @ portE to 180o and then back to 0o stopping it for one second in
between.
#include "PLL.h"
#include "tm4c123gh6pm.h"
#include <stdint.h>
int main(void){
unsigned long int i=0,k;
PLL_Init();
SysFun();
Port_Init();
SysInit();
while(1){
for (i=1; i<25;i=i+1)
{
GPIO_PORTE_DATA_R=0x05;
SysLoad(1600000);
GPIO_PORTE_DATA_R=0x06;
SysLoad(1600000);
GPIO_PORTE_DATA_R=0x0A;
SysLoad(1600000);
GPIO_PORTE_DATA_R=0x09;
SysLoad(1600000);
}
GPIO_PORTE_DATA_R=0x00;
for (i=0; i<10;i=i+1)
SysLoad(1600000);
}
}
NVIC_ST_CTRL_R = 0;
NVIC_ST_CURRENT_R = 0;//any write to current clears it
NVIC_SYS_PRI3_R=NVIC_SYS_PRI3_R&0x00FFFFFF;//priority 0
NVIC_ST_CTRL_R=0x00000005; //ENABLE WITH CORE CLOCK AND INTERRUPTS
}
void SysFun(void){
Output:
0 to 180o (T=20ms) clockwise
1second pause
180o to 0o sequence reversed 9 -> a -> 6 -> 5, implies direction changed
Inference:
- SysTick timer cannot store reload values above 0x00ffffff [24bit]
(8 bits reserved )
- SysTick timer can be used to obtain higher frequencies upto 80Mhz
- SysTickCan be used to operate switches very accurately to turn the
Stepper motor to a specific angle
Result:
● SysTick timer was implemented. Specific time delay and pulse
generator was programmed to provide pulses to turn Stepper
motor to a specific angle
● Stepper motor open loop control was performed and the switch
interface was programmed in such a way that the Stepper can be
turned to a specific angle by operating the switches.