Controllers
Controllers
Technology - 1 Project
Schematics Development and PCB design of AVR based Motion Controller for PSG
AR2 Robot
Submitted by
Brindha D – 21E109
BE EEE
The project aims to design and implement a control system for the AR2 robot using the
ATmega328P microcontroller. The AR2 robot is a versatile robotic arm used in various
industrial and research applications. This report outlines the design, development, and
implementation of the control system, including schematic and PCB design, hardware
integration, and software programming.
2) INTRODUCTION
3) METHODALOGY
3.1 PIC16F877A
3.1.1 Architecture:
• CPU (Central Processing Unit): An 8-bit CPU with an instruction set optimized for
embedded control applications.
• Memory: It includes 14 KB of Flash program memory and 368 bytes of RAM.
• Peripherals: Integrated peripherals include timers, UART (Universal Asynchronous
Receiver/Transmitter), SPI (Serial Peripheral Interface), ADC (Analog-to-Digital
Converter), and PWM modules.
• Interrupts: Supports multiple interrupt sources to handle asynchronous events
efficiently.
3.1.2 FEATURES
It features 200 ns instruction execution, 256 bytes of EEPROM data memory, self-
programming, an ICD, 2 Comparators, 8 channels of 10-bit Analog-to-Digital (A/D) converter,
2 capture/compare/PWM functions, an asynchronous serial port that can be configured as
either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave Port.
3.1.3 Pinout:
The PIC16F877A has 40 pins arranged in a dual in-line package (DIP) configuration,
providing easy access for both input and output connections.
• Power Supply: VDD and VSS pins for connecting to the power supply (typically 5V).
• I/O Ports: Multiple I/O ports (PORTA, PORTB, PORTC, PORTD) with individual pins
capable of digital I/O and some supporting analog input.
• Special Function Pins: Includes pins dedicated to programming (PGC, PGD), reset
(MCLR), and oscillator connections (OSC1, OSC2).
• Peripheral Pins: Dedicated pins for UART, SPI, ADC, and PWM modules.
The PIC16F877A microcontroller has two PWM (Pulse Width Modulation) pins available,
associated with its CCP (Capture/Compare/PWM) modules. These modules are typically
used for generating PWM signals with adjustable duty cycles, which are useful for
applications such as motor speed control, LED brightness modulation, and generating
analog-like signals from digital outputs. The specific pins designated for PWM functionality
on the PIC16F877A are typically CCP1 (RC2 pin) and CCP2 (RC1 pin). These pins are
configurable and can be programmed to generate PWM signals with different characteristics
based on the application requirements.
Code
#include <xc.h>
#define _XTAL_FREQ 20000000 //Specify the XTAL crystall FREQ
void main()
{
TRISB=0X00; //Instruct the MCU that the PORTB pins are used as Output.
PORTB=0X00; //Make all output of RB3 LOW
while(1)
{
RB3=1;
__delay_ms(100);
RB3=0;
__delay_ms(100);
}
}
Fig 2 LED blinking code
First, we have specified the external Crystal frequency using #define _XTAL_FREQ 20000000.
Then in void main () function, we instructed our MCU that we are going to use the RB3 as an
output (TRISB=0X00;) pin. Then finally a infinite while loop is used so that the LED blinking
goes on forever. In order to blink an LED we have to simply turn it ON and OFF with a
noticeable delay.
3.1.8 Hardware
3.1.10 CONCLUSION
3.2 ATMEGA328P
3.2.1 Introduction
3.2.2 Features
Core:
Memory:
Peripherals:
• Timers/Counters:
➢ Two 8-bit timers/counters.
➢ One 16-bit timer/counter with PWM (Pulse Width Modulation) support.
➢ No.of Pins 28
• Analog-to-Digital Converter (ADC):
➢ 10-bit resolution.
➢ Up to 6 channels for converting analog signals to digital values.
• Serial Communication Interfaces:
➢ USART (Universal Synchronous and Asynchronous serial Receiver and
Transmitter).
➢ SPI (Serial Peripheral Interface).
➢ I2C (Inter-Integrated Circuit).
• GPIO (General Purpose Input/Output):
➢ Multiple pins configurable as digital inputs or outputs.
• Interrupts:
➢ Multiple interrupt sources and vectors for efficient handling of asynchronous
events.
Power Management:
Packages:
• Package Types: Available in various packages including PDIP, TQFP, and QFN.
• Pin Count: Commonly available in 28-pin configurations.
Other Features:
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRD = DDRD | (1<<4) ;
DDRC = DDRC & ~(1<<0) ;
while(1)
{
if(PINC & (1<<0))
{
PORTD = PORTD | (1<<4) ;
}
else
{
PORTD = PORTD & ~(1<<4);
}
}
}
3.2.6 RESULT
Switch is connected to the pin the LED was blinking, and it connected to the RB3 pin.
Generating PWM (Pulse Width Modulation) signals using the ATmega328P microcontroller,
commonly found on Arduino boards like the Arduino Uno, is straightforward and essential
for tasks such as controlling servo motors, dimming LEDs, and more.
Timer/Counter Modules: The ATmega328P has several 8-bit and 16-bit Timer/Counter
modules (Timer0, Timer1, Timer2) that can be configured to generate PWM signals.
➢ Fast PWM: Generates a PWM signal with a fixed frequency and variable duty
cycle.
➢ Phase Correct PWM: Alternates the PWM signal up and down through the
timer period, useful in motor control applications to avoid abrupt changes.
➢ The PWM frequency is determined by the timer’s clock source and its
prescaler settings. Lower prescaler values increase the timer clock frequency
and thus the PWM frequency.
Setting PWM Duty Cycle:
➢ The duty cycle (percentage of time the signal is high within each period)
determines the effective output voltage or motor speed. It’s adjusted by
writing a value to the Timer’s Compare Register (OCRnA or OCRnB for
Timer/Counter n).
Fast PWM mode is commonly used because it allows for straightforward control of the PWM
frequency and duty cycle, making it versatile for various applications such as motor control
and LED dimming. Here’s a more detailed guide on how to implement Fast PWM mode using
the ATmega328P:
3.2.8 CODE
#include <Arduino.h>
int x;
void setup() {
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
delayMicroseconds(5000);
digitalWrite(9,LOW);
delayMicroseconds(5000);
void loop() {
//delay_ms(1000);
}
PW
M
DIRECTI
ON
Next I used A4988 driver to drive the steppermotor and finally I used Ultium designer
software to create the PCB design.
Specifications of Steppermotor
Electrical Specifications
• Phase: 2
• Steps/ Revolution: 400
• Step Angle: 0.9°
• Step Accuracy: ±5%
• Insulation Class: B, 130℃
• Insulation Resistance: 100 MegOhms
• Operating Temp.: -20℃~50℃
• IP Rating: IP 40
• Approvals: RoHS
Specifications
Description
• VDD (9): Logic supply voltage (3.3V or 5V).
• GND (5, 10, 11, 12, 13, 14, 16): Ground connections.
• VMOT (8): Motor supply voltage (8V to 35V).
• A1, A2 (1, 2): Motor coil A connections.
• B1, B2 (3, 4): Motor coil B connections.
• ENABLE (5): Enable/disable motor outputs.
• DIR (6): Direction control input.
• STEP (7): Step pulse input.
• MS1, MS2, MS3 (18, 19, 20): Microstepping mode selection.
PWM
a4988
driver ATMEGA
328P
Schematic Diagram
4.CONCLUSION
In conclusion, this report has demonstrated the practical implementation of Pulse Width
Modulation (PWM) using the ATmega328P microcontroller. We explored how PWM signals
can be generated and utilized for tasks such as LED blinking and motor control. Specifically,
we applied PWM to operate a motor in the AR2 robot, showcasing its capability to precisely
set and adjust angles, such as achieving a 90-degree position. Furthermore, the report
highlighted the development process, including the design and fabrication of a custom PCB
(Printed Circuit Board), which streamlined the integration of PWM control into a practical
application. Through these efforts, we've not only gained insights into PWM principles and
their application but also demonstrated proficiency in translating theoretical knowledge into
tangible outcomes in embedded systems and robotics.