0% found this document useful (0 votes)
4 views

ESD_5

The document outlines a lab exercise focused on controlling a DC motor's speed and direction using a SysTick timer. It explains the theory behind DC motors, the necessary calculations for reload values based on desired time delays, and provides code for implementing the control logic. The results demonstrate successful motor operation in both clockwise and anticlockwise directions based on switch inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

ESD_5

The document outlines a lab exercise focused on controlling a DC motor's speed and direction using a SysTick timer. It explains the theory behind DC motors, the necessary calculations for reload values based on desired time delays, and provides code for implementing the control logic. The results demonstrate successful motor operation in both clockwise and anticlockwise directions based on switch inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

EMBEDDED

SYSTEMS PRACTICE
LAB - 5
(12/02/2025)
DC Motor Control with
Systick Timer

S Dhanush

EC23B1035
1
Objective :
To control a passing signal with a specific time interval to control the speed and
direction of the DC motor using SysTick timer.

Theory :
A DC motor is an electromechanical converter that transforms electrical energy into
mechanical energy through the phenomenon of electromagnetism. It works due to the
interaction of a magnetic field and a conductor carrying current, producing a force that
leads to rotation. The DC motor converts the direct current into mechanical energy. It
consists of a stator that is generally a permanent magnet and the central rotating part
which is the armature coil. As the current flows through the armature windings it
magnetizes the rotor. These fields interact with the stators permanent magnetic field
and generate torque.

DC motors work on Faraday’s Law of Electromagnetic Induction and Lorentz Force Law:

-> When current flows through a coil in a magnetic field, a force is exerted on the coil,
causing it to rotate.

-> The direction of rotation follows Fleming’s Left-Hand Rule, where:

○​ Thumb → Motion (Force)


○​ Index Finger → Magnetic Field
○​ Middle Finger → Current

2
DC Motor Control :

DC Motor Interface :

Calculations : Reload value = Desired time delay/12.5 nsec =


0.5∗10−3/12.5 ∗10−9 = 400000

3
Practice Exercise :
1.SW1 on -> clockwise -> 50 %

2. SW2 on -> anti-clockwise -> 75 %

3. Both on -> clockwise -> 90%

4. Both off -> motor off

Calculations :
Case 1:- Reload value = Desired time delay / 12.5 nsec =5∗10−3 / 12.5 ∗10−9 =400000
Case 2:- Reload value = Desired time delay / 12.5 nsec =7.5∗10−3 / 12.5*10−9=600000
Case 3:- Reload value = Desired time delay / 12.5 nsec =9∗10−3 / 12.5 ∗10−9 = 720000
Case 4:- Reload value = Desired time delay / 12.5 nsec =10∗10−3 / 12.5 ∗10−9=800000

CODE :
#include "tm4c123gh6pm.h"

#include "PLL.h"

#include <stdint.h>

void PortA_Init(void){ volatile unsigned long delay;

SYSCTL_RCGC2_R |= 0x01;

delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize

GPIO_PORTA_AMSEL_R &= 0x00;

GPIO_PORTA_PCTL_R &= 0x0000000;

GPIO_PORTA_DIR_R |= 0x88;

GPIO_PORTA_AFSEL_R &= 0x00; // 6) disable alt function on PD4 and PD0

GPIO_PORTA_DEN_R |= 0x88; // 7) enable digital I/O on PD4 and PD0

4
void PortF_Init(void){ volatile unsigned long delay;

SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F

delay = SYSCTL_RCGC2_R; // allow time for clock to start

GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock GPIO Port F

GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0

// only PF0 and PF3 needs to be unlocked, other bits can't be locked

GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog on PF

GPIO_PORTF_PCTL_R = 0x00000000; // 4) PCTL GPIO on PF4-0

GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 in, PF3-1 out

GPIO_PORTF_AFSEL_R = 0x00; // 6) disable alt funct on PF7-0

GPIO_PORTF_PUR_R = 0x11; // enable pull-up on PF0 and PF4

GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital I/O on PF4-0

void SysInit(void)

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 SysLoad(unsigned long period){

NVIC_ST_RELOAD_R = period-1; // number of counts to wait

NVIC_ST_CURRENT_R = 0; // any value written to CURRENT clears

while((NVIC_ST_CTRL_R&0x00010000)==0){ // wait for count flag

5
}

unsigned long Switch;

int main(void){

/*Initialize ports and timers*/

//int i;

PLL_Init(); // 80 MHz

SysInit();

PortA_Init();

PortF_Init();

while(1)

Switch=GPIO_PORTF_DATA_R&0x11;

switch(Switch)

case 0x01:

GPIO_PORTA_DATA_R |= (0x08);

SysLoad(400000); // wait 5ms

GPIO_PORTA_DATA_R &= ~(0x08);

SysLoad(400000); // wait 5ms

break;

case 0x10:

GPIO_PORTA_DATA_R |= (0x80);

SysLoad(600000); // wait 5ms

GPIO_PORTA_DATA_R &= ~(0x80);

SysLoad(200000); // wait 5ms

6
break;

case 0x00:

GPIO_PORTA_DATA_R |= (0x08);

SysLoad(720000); // wait 5ms

GPIO_PORTA_DATA_R &= ~(0x08);

SysLoad(800000); // wait 5ms

break;

default:

GPIO_PORTA_DATA_R &= (0x00);

break; } } }

Output :

7
Inference : The output waveform displays the PWM signal
corresponding to clockwise and anticlockwise rotations and motor off in the
DC motor. To achieve this configuration, we configure the Systick Timer
with specific reload value to ensure accurate rotation of the DC motor.

In this code, the coil rotation value for SW1 is given as

Reload value = Desired time delay / 12.5 nsec =5∗10−3 / 12.5 ∗10−9 =400000

Which will give the duty cycle of 50% and rotates the DC motor in
clockwise direction.

For SW2 is given as

Reload value = Desired time delay / 12.5 nsec =7.5∗10−3 / 12.5*10−9=600000

8
Which will give the duty cycle of 75% and rotates the DC motor in
anticlockwise direction.

For Both on is given as

Reload value = Desired time delay / 12.5 nsec =9∗10−3 / 12.5 ∗10−9 = 720000

Which will give the duty cycle of 90% and rotates the DC motor in
clockwise direction when both the switches SW1 and SW2 are kept on.

For Both off is given as

Reload value = Desired time delay / 12.5 nsec =10∗10−3 / 12.5 ∗10−9=800000

Which will turn off the DC motor when both the switches are turned off.

The Switch condition should be used to achieve this configuration in the


code and a break should be used to iterate the switch after execution of the
given duty cycles in the DC motor.

Result : The Control sequence has been successfully generated to rotate


the DC motor clockwise and anticlockwise corresponding to the given duty
cycle.

You might also like