Microcontroller basics Embedded systems for mortals.

Slides:



Advertisements
Similar presentations
Sensing and Control.
Advertisements

EMS1EP Lecture 8 Pulse Width Modulation (PWM)
Servo Background Servos provide control of rotary position Servos are used extensively in the remote control hobby world for: Aircraft (flaps, ailerons,
Encoders, Motors, Power, Mini Project #1 10/24/2014.
Basic DC Motor Circuits
Servos The material presented is taken from a variety of sources including:
L.
Living with the Lab Using servos with an Arduino EAS 199A Fall 2011.
Secret Door Knock Detector
SENIOR DESIGN 10/16.
Micromouse Meeting #3 Lecture #2 Power Motors Encoders.
Pulse Width Modulation (PWM) LED Dimmer Circuit
1 Motors & Motor Controllers ECE AC or DC Motors AC –Few robots use AC except in factories –Most of those that use AC first convert to DC DC –Dominates.
Servo Motors # A servo is a motor that you can position at any angle very accurately. # Servos have a limited servo range; most servos have a range of.
1 Servo Motor. 2 Overview A servo motor is a motor that is only capable of rotating 180 degrees A servo motor is controlled by giving it an angle to proceed.
L.C. Technology Servo Motor Control / Genie Software
Applied Control Systems Robotics & Robotic Control
Manufacturing Advanced Design Applications Manufacturing © 2014 International Technology and Engineering Educators Association, STEM  Center for Teaching.
Microcontroller Hands-on Workshop #3 Ahmad Manshad New Mexico State University Institute of Electrical and Electronics Engineers November 7, 2009.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
CS 478: Microcontroller Systems University of Wisconsin-Eau Claire Dan Ernst Hybrid I/O – Pulses.
PWM Circuit Based on the 555 Timer. Introduction In applications LED Brightness Control we may want to vary voltage given to it. Most often we use a variable.
Pulse Width Modulation (PWM). 100% Pulse Width Modulation (PWM) 0% On the chipKIT there are 490 periods per second. Use analogWrite(pin, value) to control.
Electrical Actuation System Lecture 9 (Chapter 9).
Microprocessoren lesson 6. PWM /motor control/servo.
Using Hobby Servos with the Arduino living with the lab © 2012 David Hall.
Servos The material presented is taken from a variety of sources including:
Arduino Circuits and Code. int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, LOW); delay(1000); digitalWrite(ledPin,
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
1 4-Integrating Peripherals in Embedded Systems (cont.)
PIC18F4431. PIC18F1330 Infrared Encoder/Decoder.
PWM: Pulse Width Modulation © 2014 Project Lead The Way, Inc.Digital Electronics.
Robot Project by Ahmad Shtaiyat Supervised by Dr. Salem Al-Agtash.
SAMI MAKERSPACE MAKE: AN ELECTRONICS WORKSHOP. SERVOS Precise rotations.
Analog Output Materials: animatronic head Processing Quiz HW: code links.
Microcontroller basics Embedded systems for mortals.
Microcontroller basics Embedded systems for mortals.
Robotics Grant Agreement No LLP UK-LEONARDO-LMP Project acronym: CLEM Project title: Cloud services for E-Learning in Mechatronics Technology.
Istituto Tecnico Industriale A.Monaco EURLAB Moving a robot simple example program to control a DC-Motor Next - Press the button (left)
Istituto Tecnico Industriale A.Monaco EURLAB Control a Servo Motor If you want to swing an robot arm or … steer a robot you need a special motor (Servo).
INTERNET OF EVERYTHING SDU 2016 Week 9. Physical Output  Make things move by controlling motors with Arduino  Servo-motors  Rotary actuator that allows.
DC motor principles Speed control Direction Stepper motor principles
Pulse-Width Modulation: Simulating variable DC output
Arduino Application: Speed control of small DC Motors
1 Microcontrollers. 2 Programmers work in the virtual world Machinery works in the physical world Microcontrollers connect the virtual and physical world.
Motors & Motor Controllers
Microcontroller basics
Introduction to Motors, servos and steppers
Controlling Servos with the Arduino
Outline Introduction to digital-to-analog converter (DAC)
Assist. Prof. Rassim Suliyev - SDU 2017
CU ATLAS Practical electronics Motion and Servos
Microcontroller basics
If you want to swing an robot arm or …
Microcontroller basics
Servo Motor.
Using servos.
Microcontroller basics
Servos The material presented is taken from a variety of sources including:
Arduino - Introduction
Control a motors angular position with a flex sensor
Servos The material presented is taken from a variety of sources including:
Arduino Application: Speed control of small DC Motors
Secret Door Knock Detector
Arduino : Introduction & Programming
Assist. Prof. Rassim Suliyev - SDU 2018
Sensors and actuators Sensors Resistive sensors
UNIT 11: RC-SERVOMOTOR CONTROL
Pulse-Width Modulation: Simulating variable DC output
Servo Motor.
Presentation transcript:

Microcontroller basics Embedded systems for mortals

Lesson 4 PWM Transistors and Fets Motors Servo DC Stepper

FETs FET = Field Effect Transistor 2 different types with 2 different modes: N-FET and P-FET Enhancement and depletion mode Enhancement Mode Depletion Mode

FET Applications Most commonly used as an electric switch High power and switching speeds possible N-Fet can be used to “cut” the ground wire and P-Fet to “cut” the voltage source wire

PWM (Pulse Width Modulation) Basic terms Duty cycle = Pulse Width / Wave Period

Duty cycle 100 % 75 % 50 % 25 % 0 % ←Ideal Square Wave

PWM Applications Servomotor angle control DC motor speed control LED Dimming Audio generation Digitally generating analog voltages (requires filtering)

PWM with Teensy Total of 9 pins with PWM capability 4 different PWM modes in total: CTC Fast PWM Phase correct PWM Phase and frequency correct PWM Requires using of internal interrupts and timers if you want to modify the frequency of PWM Lot of libraries and examples available for multiple applications for normal PWM

Servo motor Simple feedback motor that obtains a certain position based on the input signal Position is determined by the duty cycle (= pulse width) Without feedback a servo motor is basically a normal motor, but speed is then controlled with the PWM signal

Example 12 – Breadboard setup Using servo motor External power supply Power supply and Teensy need to be in the same ground! Brown = GND Red = + Volt Orange= sign

Example 12: Code #include Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position void setup() { myservo.attach(16); // attaches the servo on pin 9 to the servo object } void loop() { for(pos = 0; pos <= 120; pos += 1) // goes from 0 degrees to 120 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 120; pos>=0; pos-=1) // goes from 120 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position }

Turn the Servo Use a potentiometer to determine the postion of the servo Servo still has the same wiring

Turning the Servo #include Servo myservo; // create servo object to control a servo int potpin = 38; // analog pin used to connect the potentiometer (F0/A0) int val; // variable to read the value from the analog pin void setup() { myservo.attach(16); // attaches the servo on pin 16 (C6) to the servo object } void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 0, 1023, 0, 120); // scale it to use it with the servo (value between 0 and 120) myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }

DC motor control Can change speed according to voltage (PWM) or direction Requires an H-bridge for direction control Build yourself Get a DC motor driver that has it

DVR8833 Dual motor driver

Example 13: Breadboard setup

Example 13: Simple DC int a1 = 15; //First directrion pin C5 int a2 = 16; //Second directrion pin C6 int spd = 100; void setup(){ //Set both PWM pins as outputs pinMode(a1, OUTPUT); pinMode(a2, OUTPUT); } void loop(){ //First direction digitalWrite(a1, LOW); analogWrite(a2, spd); delay(2000); //Second direction digitalWrite(a2, LOW); analogWrite(a1, spd); delay(2000); }

DC – adjustable 1/2 int a1 = 15; //First directrion pin C5 int a2 = 16; //Second directrion pin C6 int spd = 0; void setup(){ //Set both PWM pins as outputs pinMode(a1, OUTPUT); pinMode(a2, OUTPUT); Serial.begin(9600); } void loop(){ for(spd=0; spd <= 250; spd += 1) //first dircetion, acceleration to 150 { digitalWrite(a1, LOW); analogWrite(a2, spd); Serial.println(spd); delay(20); }

DC – adjustable 2/2 for(spd=250; spd >= 0; spd -= 1){ //first direction, deceleration to 0 digitalWrite(a1, LOW); analogWrite(a2, spd); Serial.println(spd); delay(20); } for(spd=0; spd <= 250; spd += 1) //Second dircetion, acceleration to 150 { digitalWrite(a2, LOW); analogWrite(a1, spd); Serial.println(spd); delay(20); } for(spd=250; spd >= 0; spd -= 1){ //Second direction, deceleration to 0 digitalWrite(a2, LOW); analogWrite(a1, spd); Serial.println(spd); delay(20); }

Stepper motor Our motor is a 12 Volt 200 step motor With a stepper you can control speed, direction and step amount 200 steps / 360 deg = 1 step is 1.8 deg Bipolar motor: two windings Red/Yellow Green/Grey No polarity! (no ”+” or ”-”)

Example 14: Breadboard setup

Exmaple 14: Stepper motor 1/2 //Controlling a Stepper mtor #define DIR_PIN 24 //Dir pin to B4 #define STEP_PIN 25 //Step pin to B5 void setup() { pinMode(DIR_PIN, OUTPUT); pinMode(STEP_PIN, OUTPUT); } void loop(){ //rotate a specific number of degrees rotateDeg(360, 1); delay(1000); rotateDeg(-360,.1); //reverse delay(1000); }

Exmaple 14: Stepper motor 2/2 void rotateDeg(float deg, float speed){ //speed is any number from.01 -> 1 with 1 being fastest - Slower is stronger if (deg > 0){ // define direction according to deg (negative for reverse) digitalWrite(DIR_PIN, HIGH); } else{ digitalWrite(DIR_PIN, LOW); } int steps = abs(deg)*(1/0.225); //How many steps we want to take? e.g. // 360*(1/0.225) = 1600 microsteps float usDelay = (1/speed) * 80; //Speed defines the delay between pulses for(int i=0; i < steps; i++){ //Toggle the step pin ON and OFF with the desired // delay = speed digitalWrite(STEP_PIN, HIGH); //Step pin ON delayMicroseconds(usDelay); digitalWrite(STEP_PIN, LOW); //Step pin OFF delayMicroseconds(usDelay); }

Comparison of motors Servo -Angle is adjustable -Active feedback Servo motor 6 V: 10 € -No need for a driver DC -Speed is adjustable -No feedback -Dual motor driver DRV8833: 5€ DC motor we used: 2 € Stepper -Speed and steps (=length of the move) are adjustable -No feedback Stepper motor 12 V 200 steps: 15 € Stepper motor Driver: 15 €

 The bigger the motor,  The more it cost,  The more power Caution: Know what type of motor you need and do not pay more for attributes or power that you don’t need!