0% found this document useful (0 votes)
7 views17 pages

Mini Project

This document details a mini project conducted by students at the Ho Chi Minh City University of Technology, focusing on controlling an LCD and a motor using PWM pulses and an H-bridge. It includes sections on project preparation, platform design using VHDL, and the implementation of code for the LCD and motor control. The project aims to blink a message on the LCD and control motor speed through PWM signals, demonstrating practical applications of electronics and programming.

Uploaded by

ngominhnhan543
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views17 pages

Mini Project

This document details a mini project conducted by students at the Ho Chi Minh City University of Technology, focusing on controlling an LCD and a motor using PWM pulses and an H-bridge. It includes sections on project preparation, platform design using VHDL, and the implementation of code for the LCD and motor control. The project aims to blink a message on the LCD and control motor speed through PWM signals, demonstrating practical applications of electronics and programming.

Uploaded by

ngominhnhan543
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

VIET NAM NATIONAL UNIVERSITY

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

Mini Project

Class: TT01 --- Group 9 --- Course 212

Instructor: Nguyễn Trung Hiếu

Student’s name ID NUMBER


Phạm Lê Anh Tuấn 1951109
Kiều Nguyễn Minh Triết 1951106
Nguyễn Minh Hiển 1951140

16-Jun-2022, Ho Chi Minh city


Contents
1. LCD Blinking.................................................................................................................2

2. Motor with PWM pulses to the H-bridge....................................................................3

3. Working on the project.................................................................................................5

3.1 Preparation................................................................................................................5

3.2 Platform design VHDL..............................................................................................6

3.3 Working on Project....................................................................................................6

Result................................................................................................................................14

Reference..........................................................................................................................16

Page 1 of 17
1. LCD Blinking
- For this project, we'll use an LCD 1602 and the DE10 kit to blink the phrase
"Hello World!!!" once every second.
This task's flow chart is as follows:
Figure 1. Flow chart of the Problem No.1
The LCD Module
HD44780 LCD modules almost always have a 14-pin
microcontroller/microprocessor interface. Some displays may include more pins for
backlighting or other functions, but the first 14 pins are still used as the interface.

Page 2 of 17
The power for the LCD module is provided by the first three pins. Pin 1 is GND,
and it's connected to the Launchpad's GND. Pin 2 is VCC, and it is connected to the
Launchpad's +5V VBUS. The LCD Display Bias is connected to pin 3. To control the
voltage, a 10k potentiometer is connected to this pin. The contrast of the display can be

modified by altering the voltage or duty cycle of pin 3. With a voltage between 5V and
10V, most character LCDs can produce high display contrast.
Firgure 2. LCD module QAPASS

2. Motor with PWM pulses to the H-bridge


The speed of an electric motor is determined by the voltage source that we provide
it with.
Figure 3. Motor model run on Proteus
In this project, though, we'll utilize PWM pulses to control the motor's speed. To
do so, we'll need to connect and disconnect the voltage source from the motor using an
H-bridge. An H-bridge is a simple circuit that allows you to control the direction of a DC
motor. The H-bridge concept is as follows:

Page 3 of 17
Depending on how the plus and minus are connected, a DC motor can spin
backward or forward.
Switch 1,4 closed Switch 2,3 closed

In actuality, a
transistor with
adequate biasing can
function as a switch,
allowing it to toggle
between the two states of
an on/off switch. This transistor design has been used in an H-bridge to drive a motor
clockwise and anticlockwise.

We can regulate the speed of the motor by changing the time that we deliver
electricity to the motor in one cycle, thanks to the H-bridge design employing transistors.
For example, consider the following signal to the motor:

Page 4 of 17
If we provide a motor with a voltage source that is not constant but consists of
PWM pulses, the motor will spin at the same speed as it would with a constant voltage
source Vm if the frequency of the pulses is high enough.

Tm
With Vm = . Vcc ( Tm = duty cycle) = D.Vcc (D<=1)
T

We can easily modify the speed of the motor using the equation above by adjusting
the time that we deliver voltage to the motor (duty cycle).

3. Working on the project


3.1 Preparation
FPGA Kit
LCD
Motor
H-bridge module L289

Page 5 of 17
3.2 Platform design VHDL

Page 6 of 17
3.3 Working on Project
VHDL code

Page 7 of 17
Page 8 of 17
Page 9 of 17
Eclipse code
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/alt_alarm.h>
#include <altera_avalon_pio_regs.h>
#include <system.h>
#include <stdio.h>
#include <unistd.h>

#define WRITE(base,data) IOWR_ALTERA_AVALON_PIO_DATA(base, data)


#define READ(base) IORD_ALTERA_AVALON_PIO_DATA(base)

char hello[] = " Hello World!!! ";


char freq[] = "Freq: ";
char f[] = "10000";
char Hz[] = "Hz";
char duty[] = "Duty: ";
char space[] = " ";

Page 10 of 17
char d[3];
//extern alt_u32 T; //Period (us)
//extern alt_u32 D; //duty cycle (%)
//extern unsigned short sw;
char status_Switch;

void trans(alt_u32 num)


{
alt_u32 charac, temp;
temp = num;
int i = 1;
alt_u32 t = 0;
for(int i = 1; i >= 0; i-- )
{
if(temp%10 != 0)
{
charac = temp%10;
temp = temp - charac;
t++;
}
else if (temp%10 == 0 && t == 0)
{
charac = 0;
t++;
}
else
{
charac = temp/10;
}
char c = charac + '0';
d[i] = c;
}
}

unsigned short sw = 0; //store switch input


alt_u32 T = 10000; //Period (us)
alt_u32 D; //duty cycle (%)

void lcd_cmd(unsigned char data)


{
WRITE(LCD_DATA_BASE,data); //send data to D0-D7
WRITE(LCD_CONTROL_BASE,0b100); //set Enable to 1
usleep(200);
WRITE(LCD_CONTROL_BASE,0); //set Enable to 0
}

void lcd_data(unsigned char data)


{
WRITE(LCD_DATA_BASE,data); //send data to D0-D7
WRITE(LCD_CONTROL_BASE,0b101); //set RS to 1 and Enable to 1
usleep(200);
WRITE(LCD_CONTROL_BASE,0b001); //set Enable to 0
}

void lcd_init()
{
lcd_cmd(0x38); //Send function set

Page 11 of 17
usleep(39); //Wait 39 us

lcd_cmd(0xc); //Send display on cursor off control


usleep(39); //Wait 39 us

lcd_cmd(0x6); //Set entry mode


usleep(39); //Wait 39 us

lcd_cmd(0x1); //Send display clear


usleep(1640); //Wait 1.64 ms
}

alt_u32 LCDCB(void* context)


{
//blink hello world when switch 0 is on
if(status_Switch == 0b01)
{
static bool toggle = true;
if(toggle)
{
for(int i = 0 ; i < 16 ;i++)
lcd_data(hello[i]); //send string to lcd
toggle = !toggle; //change state
}
else
{
lcd_cmd(0x01); //clear screen
toggle = !toggle; //change state
}
}
else if(status_Switch == 0x02 || status_Switch == 0x04 || status_Switch
== 0x08 || status_Switch == 0x10 || status_Switch == 0x20 || status_Switch ==
0x40 || status_Switch == 0x80 || status_Switch == 0x100 )
{
trans(D);
for(int i = 0 ; i < strlen(freq) ;i++)
lcd_data(freq[i]);
for(int i = 0 ; i < strlen(f) ;i++)
lcd_data(f[i]);
for(int i = 0 ; i < strlen(Hz) ;i++)
lcd_data(Hz[i]);
lcd_cmd(0xc0);
for(int i = 0 ; i < strlen(duty) ;i++)
lcd_data(duty[i]);
for(int i = 0 ; i < 2 ;i++)
lcd_data(d[i]);
lcd_data('%');
for(int i = 0 ; i < strlen(space) ;i++)
lcd_data(space[i]);
}

else
{lcd_cmd(0x01);}

return alt_ticks_per_second();
}

Page 12 of 17
alt_u32 L298CB(void* context)
{
//Duty cycle range is 18% - 98%
if(D > 98) D = 98;
else if(D < 18) D = 18;
//Run motor when switch 1 is on
if(status_Switch != 0x02 && status_Switch != 0x04 && status_Switch !=
0x08 && status_Switch != 0x10 && status_Switch != 0x20 && status_Switch !=
0x40 && status_Switch != 0x80 && status_Switch != 0x100) return
alt_ticks_per_second()*0.001;

//create PWM signal


if(status_Switch == 0x02 || status_Switch == 0x04 || status_Switch ==
0x08 || status_Switch == 0x10 || status_Switch == 0x20 || status_Switch ==
0x40 || status_Switch == 0x80 || status_Switch == 0x100)
{
WRITE(H_BRIDGE_BASE,0b10);
usleep(T*D/100);
WRITE(H_BRIDGE_BASE,0b00);
return alt_ticks_per_second()*0.001;
}
}

int main()
{
static alt_alarm alarm_H_bridge, alarm_LCD;

alt_alarm_start(&alarm_H_bridge,
alt_ticks_per_second()*0.001,L298CB,NULL);

lcd_init();
alt_alarm_start(&alarm_LCD, alt_ticks_per_second(),LCDCB,NULL);

while(1)
{
status_Switch = READ(SWITCH_BASE);

if(status_Switch == 0x01)
{
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,1);
}
else if(status_Switch == 0x02)
{
D = 20;
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,2);
}
else if(status_Switch == 0x04)
{
D = 40;
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,4);
}
else if(status_Switch == 0x08)
{
D = 60;
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,8);
}

Page 13 of 17
else if(status_Switch == 0x10)
{
D = 80;
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,16);
}
else if(status_Switch == 0x20)
{
D = 90;
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,32);
}
else if(status_Switch == 0x40)
{
D = 100;
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,64);
}
else
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,0x00);

}
return 0;
}

Result

Page 14 of 17
Reference
- Interfacing LCD display
- LCD datasheet
- L268 H bridge

Page 15 of 17
Page 16 of 17

You might also like