DC motors are rotary motors that convert electrical signals into mechanical motion.
DC motors are also one of the most useful peripheral devices in the embedded domain, we can use the DC motors from our academic projects to toys and gadgets sold in the market.
In this article, we will talk about the interfacing of DC motor to the PIC18F4520 controller.
We will cover the topics in the following ways:-
About the Task
Required components
software tools
circuit diagram
writing code for the controller
uploading the hex file to the controller
Simulating the project
About the project
In this interfacing task, we will control the rotation of the DC motor with a push button. When the push button is pressed the motor will rotate in a clockwise direction otherwise it will rotate in an antilock wise direction.
Required components
For the simulation, the components which are required are:-
The circuit diagram for the interfacing is given below
In the circuit diagram you can see, the L293D motor driver is connected to the C0 and C1 pin of the PORTC and the push button is connected to the B0 pin of the PORTB. The DC motor is connected to the output pin of the motor driver.
Writing code for the controller
After connecting all the circuit components, now open your MPlab IDE and write the code given below.
code
#include <xc.h>
#define _XTAL_FREQ 20000000
#define button RB0
#define relay RC0
void main()
{
TRISB0=1;
TRISC0=0;
if(button==1)
{
relay=1;
}
else
{
relay=0;
}
}
After writing the code all you need is to run, execute and generate the HEX file.
Upload Hex file to the controller
To upload the generated Hex file all you need is to double click on the controller and select the program file.
Don't forget to change the clock frequency from 4 to 20 Mhz.
Simulate the project
To simulate the project all you need is to click on the play button on the bottom left corner of the simulator.
What is machine learning(ML)? Machine learning is a subset of artificial intelligence. Machine learning enables computers or machines to make data-driven decisions rather than being explicitly programmed for a certain task. These programs or algorithms are designed in a way that they learn and improve over time when are exposed to new data. Examples:- 1. Product recommendations While checking for a product did you noticed when it recommends a product similar to what you are looking for? or did you noticed "the person bought this product also bought this" combination of products? How are they doing this recommendation? This is machine learning. 2. Email spam and malware filtering There are a number of spam filtering approaches that email clients use. To ascertain that these spam filters are continuously updated they are powered by machine learning. 3. Online customer support A number of websites nowadays offer the option to chat with customer support representati...
The PIC18 timer is divided into 4 types Timer 0 Timer 1 Timer 2 Timer 3 PIC18 timers can be used to generate a time delay or as a counter to count external event happening outside the microcontroller. In this article, we will see how to generate a time delay by programming the PIC18 timer. Timer 0 The timer 0 module has the following features Software is scalable as an 8 bit or 16-bit timer/counter. Readable and writable Dedicated 8 bit software programmable Prescaler Clock source selectable to be internal or external Edge select for external clock Register required for Timer 0 Control register Each timer has a control register called TCON to set the various timer operation modes. T0CON is an 8-bit register used for control of timer 0. TOCON TMR0ON (Timer0 on/off control bit) 1 = Enable timer 0 ...
Hi... today we will talk about another important component used in the embedded domain called a relay. Relays are electric switch which uses electromagnetism to either form or breaks the existing circuits. With the help of a relay, you can trigger a high voltage operation by a low voltage input signal. Relay is a highly versatile component that is as effective in a complex circuit as in a simple circuit. In this article, we will talk about how to interface relay with PIC18 controller. We will cover the topics in the following points: About the interfacing task Software tools used Required components Circuit diagram Code for controller Upload the HEX file Run simulation About the interfacing task In the interface relay task, with the help of a push-button, we will trigger the relay to control the lighting of the bulb which is of higher voltage. When we press the push button the microcontroller will trigger the relay to change its state, when the relay changes its state from normally clo...