Project 1 - Controlling a DC motor using PWM and monitoring its Running status
Project 1 - Controlling a DC motor using PWM and monitoring its Running status
Ans:
Code:
Overview of the Project:
1. Initialization:
- Initializes the LCD module and motor control circuit.
- Sets up the necessary pins for data and control lines of the LCD.
- Defines pins for controlling the L293 motor driver.
2. LCD Display:
- Uses LCD functions to write characters, strings, and control the cursor position.
- Demonstrates scenarios by updating the LCD display messages
3. Motor Control:
- Initializes the L293 motor driver's control pins.
- Utilizes PWM for motor speed control.
- Sets direction and speed based on user input.
4. Main Loop:
- Runs an infinite loop to showcase different motor scenarios.
- Updates the LCD display to reflect the motor's status.
Goals:
1. Initialize and control an LCD display to show motor status and messages.
2. Configure motor control pins and use PWM to control motor speed using the L293 motor driver.
3. Illustrate various motor scenarios (forward, backward, stopped) on the LCD display.
4. Integrate potentiometer input to adjust motor speed dynamically.
5. Demonstrate motor direction and speed control using the AVR ATmega328 microcontroller.
Key Highlights of the Project:
1. LCD Initialization: The code initializes the LCD module to display messages using custom functions like `LCD_init`, `LCD_command`, `LCD_writeChar`, `LCD_writeString`, and `LCD_setCursor`.
2. Motor Control: The L293 motor driver is used to control the motor's speed and direction. The `initMotor` function sets up the necessary pins, and the `controlMotor` function adjusts the motor's behavior based on speed input.
3. ADC Input: The code reads analog input from a potentiometer using the ADC module to control the motor's speed. The potentiometer value is converted to a motor speed value.
4. LCD Display: The LCD displays status messages indicating whether the motor is running forward, backward, or stopped. The display updates dynamically based on motor behavior.
5. PWM for Motor Speed: The code employs PWM (Pulse Width Modulation) to control the motor's speed using Timer1's output compare register OC1B.
6. Scenario Demonstration: The code demonstrates various scenarios, such as running the motor forward, running it backward, and stopping it, accompanied by relevant LCD display messages.
7. Clearing LCD: The `LCD_command(0x01);` line is used to clear the LCD screen after displaying messages, providing a clean display for the next scenario.
8. Pin Configurations: The code defines clear pin assignments for the LCD control lines, L293 motor driver control pins, and ADC input, enhancing readability and configurability.
9. Infinite Loop: The program runs in an infinite loop, continuously demonstrating motor scenarios and updating the LCD display.
10. Code Readability: The code utilizes meaningful function names, clear comments, and organized sections, making it easy to understand and modify.
11. Effective Use of Delay: Delays are used appropriately with `_delay_ms` and `_delay_us` to control timing within the program.
12. Efficient Memory Usage: The code efficiently uses memory by declaring necessary variables and functions while avoiding unnecessary overhead.
Deliverables of this project:
1. Motor Control and Direction: The code provides motor speed control and direction change using the L293 motor driver. It demonstrates the ability to run the motor both forward and backward.
2. LCD Display: The code utilizes an LCD display to show the motor's status and actions. It displays messages like "Running forward" and "Running backward" to indicate the motor's direction.
3. Initialization: The code initializes the LCD, motor control circuit, and PWM for motor speed control, creating a functional setup.
4. Loop and Scenarios: The main loop continuously updates the LCD with different motor scenarios, showcasing how the motor reacts to speed changes and direction reversals.
5. User Interaction: Users can observe the motor's behavior and direction changes on the LCD display in response to the potentiometer input.
Expected Outcomes:
- The LCD will be initialized and the display cleared.
- The motor will run forward, and the LCD will display "Running forward" for 10 seconds.
- The motor will run backward, and the LCD will display "Running backward" for 10 seconds.