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

Controllers

Uploaded by

Brindha 2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Controllers

Uploaded by

Brindha 2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Department of Robotics and Automation Engineering

PSG College of Technology


PSG – MHI Industry Accelerator Project
Funded by Ministry of Heavy Industries, Government of India

Technology - 1 Project

Development of Robotic Controller for Welding Applications

Internship Report - 2024

Schematics Development and PCB design of AVR based Motion Controller for PSG
AR2 Robot

Submitted by

Brindha D – 21E109

BE EEE

PSG College of Technology

Co – Principal Investigator Principal Investigator


Schematics Development and PCB design of AVR based Motion
Controller for PSG AR2 Robot
1) PROJECT DESCRIPTION

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

I began learning about the PIC16F877A microcontroller, developed by Microchip


Technology, is a prominent member of the PIC (Peripheral Interface Controller) family,
known for its widespread use in embedded systems. This 8-bit microcontroller offers a
robust architecture with a rich array of features, making it highly versatile for various
applications. Despite its strengths, such as a wide range of peripherals and ease of
programming, the PIC16F877A has only two PWM (Pulse Width Modulation) pins. This
limitation prompts many developers to consider alternatives like the ATmega328P
microcontroller. The ATmega328P, used in platforms like the Arduino Uno, offers more PWM
channels, making it suitable for applications requiring multiple PWM outputs, such as
controlling servo motors in robotics. This distinction is particularly relevant in projects like
operating the AR2 robot, where precise PWM signals are crucial for motor control and
overall system performance.

3) METHODALOGY

3.1 PIC16F877A

3.1.1 Architecture:

The PIC16F877A microcontroller is based on Harvard architecture and operates at a clock


speed of up to 20 MHz. Key features of its architecture include:

• 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.

Fig 1 PINOUT PIC16F877A

The pinout includes:

• 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.

3.1.4 PWM Pins:

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.

3.1.5 LED BLINKING USING PIC16F877A

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.6 Software Simulation in Proteus

Fig 3 Software simulation


3.1.7 Softwares used
MPLAB X
Pic kit 3
Proteus

3.1.8 Hardware

Fig 4 LED blinking in hardware


3.1.9 RESULT

The LED was blinking, and it connected to the RB3 pin

3.1.10 CONCLUSION

Since PIC16F877A has 2 PWM pins so we move on to the ATMEGA328P

3.2 ATMEGA328P

3.2.1 Introduction

ATmega328/328P is an Advanced Virtual RISC (AVR) microcontroller. It supports 8-bit data


processing. ATmega-328/328P has 32KB internal flash memory. ATmega328/328P has 1KB
Electrically Erasable Programmable Read-Only Memory (EEPROM). And it has 6 PWM pins.
Moreover, ATmega-328 has 2KB Static Random Access Memory (SRAM). ATmega328/328P
is a 28-Pin AVR Microcontroller, manufactured by Microchip, follows RISC Architecture and
has a flash-type program memory of 32KB.

3.2.2 Features

Core:

• CPU: 8-bit AVR RISC (Reduced Instruction Set Computing) architecture.


• Clock Speed: Up to 20 MHz with external crystal oscillator.
• Registers: 32 general-purpose 8-bit registers for fast operation.

Memory:

• Flash Memory: 32 KB of in-system self-programmable flash memory for program


storage.
• SRAM: 2 KB of static RAM (SRAM) for data storage.
• EEPROM: 1 KB of EEPROM for non-volatile data storage.

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:

• Power Supply: Typically operates from 1.8V to 5.5V.


• Sleep Modes: Several low-power modes to reduce power consumption during idle or
low-power operation.

Development and Programming:

• Programming: Supports in-circuit programming via SPI.


• Debugging: DebugWIRE interface for on-chip debugging (some variants).
• Bootloader: Often used with a bootloader for easy firmware updates over UART.

Packages:

• Package Types: Available in various packages including PDIP, TQFP, and QFN.
• Pin Count: Commonly available in 28-pin configurations.

Other Features:

• Watchdog Timer: Built-in watchdog timer for system reliability.


• Temperature Sensor: Internal temperature sensor for temperature measurement.
3.2.3 Pin Configuration

Fig 5 ATMEGA328P pinout

1. PC6 (RESET): Reset pin, active low.


2. PD0 (RXD): Serial Receive Data (USART).
3. PD1 (TXD): Serial Transmit Data (USART).
4. PD2 (INT0): External Interrupt 0.
5. PD3 (INT1): External Interrupt 1.
6. PD4 (OC1B): Output Compare Match B for Timer/Counter1.
7. VCC: Supply voltage (typically 5V or 3.3V).
8. GND: Ground.
9. XTAL1: Input to the inverting Oscillator amplifier and input to the internal clock
operating circuit.
10. XTAL2: Output from the inverting Oscillator amplifier.
11. PD5 (OC1A): Output Compare Match A for Timer/Counter1.
12. PD6 (OC2B): Output Compare Match B for Timer/Counter2.
13. PD7 (OC2A): Output Compare Match A for Timer/Counter2.
14. PB0 (ICP1): Input Capture Pin for Timer/Counter1.
15. PB1 (OC1A): Output Compare Match A for Timer/Counter1.
16. PB2 (SS/OC1B): Slave Select pin for SPI bus, and Output Compare Match B for
Timer/Counter1.
17. PB3 (MOSI/OC2): Master Out Slave In pin for SPI bus, and Output Compare Match B
for Timer/Counter2.
18. PB4 (MISO): Master In Slave Out pin for SPI bus.

3.2.4 LED Blinking using ATMEGA328P


Fig 6 led blinking using ATMEGA328p both software and hardware

3.2.5 Switch LED interface with AVR Microcontroller

#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);
}
}
}

Fig 7 led blinking code


Fig 8 LED blinking Software simulation

3.2.6 RESULT

Switch is connected to the pin the LED was blinking, and it connected to the RB3 pin.

3.2.7 PWM Generation using ATMEGA328P

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.

PWM Modes: The Timer/Counter modules support different PWM modes:

➢ 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.

Setting PWM Frequency:

➢ 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:

Setting Up Fast PWM on ATmega328P

Choose a PWM Pin:


➢ Decide which pin you want to use for PWM output. On the Arduino Uno, pins
3, 5, 6, 9, 10, and 11 are typically used for PWM.

3.2.8 CODE

#include <Arduino.h>

int x;

void setup() {

pinMode(9,OUTPUT);
pinMode(8,OUTPUT);

digitalWrite(8,LOW);

int desiredAngle = 90;

int steps = desiredAngle * 1.1111 *48;

for(x = 0; x < steps; x++) //

digitalWrite(9,HIGH);

delayMicroseconds(5000);

digitalWrite(9,LOW);

delayMicroseconds(5000);

void loop() {

//delay_ms(1000);

}
PW
M
DIRECTI
ON

Fig 9 PWM generation coding and hardware

3.2.9 Softwares used

• Any software is used to create hex file


• Arduino

Next I used A4988 driver to drive the steppermotor and finally I used Ultium designer
software to create the PCB design.

Specifications of Steppermotor

• Frame Size: NEMA 17


• Step Angle: 0.9°
• Holding Torque: 190 mN•m~550 mN•m
• Low vibration; Low noise
• Higher motor efficiency

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

3.3 A4988 Driver

Specifications

Motor output voltage 8V – 35V

Logic input voltage3V – 5.5V

Continuous current per phase - 1A

Maximum current per phase – 2A

Microstep resolution full, 1/2, 1/4, 1/8 and 1/16

3.3.1 Pin out

Fig 10 A4988 driver pinout

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

Fig 12 STEPPER MOTOR INTERFACING USING A4988


Fig 13 INTERFACING WITH AR2 ROBOT

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.

You might also like