micro controllers - embedded programming with real hardware

Post on 16-Jul-2015

608 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Team Emertxe

Microcontrollers

Microcontrollers

● Introduction

● System Development Concept (Low Level)

● Understanding Target

● Work Environment and Development Guidelines

● Lets Roll Out on Interfaces

Introduction

Introduction

● What is a Microcontroller

● General Architectures

● µP vs µC

● Choosing a Microcontroller

IntroductionWhat is a Microcontroller?

● An Integrated Circuit which is capable of being programmed to preform a specific task.

● The design normally has restrictions on its

– Memory Size

– I/O Capabilities

– Peripheral Functions etc.,

IntroductionGeneral Architectures

● Shared signals and memory for code and data

● Physically separate signals and storage for code and data

IntroductionµP vs µC - Microprocessors

● All separate components

● More flexible

● More design complexity

IntroductionµP vs µC - Microcontroller

● All components in single chip

● Less flexible

● Less design complexity

IntroductionChoosing a Microcontroller

● Applications

● Performance

● Price

● Availability

● Availability of Tools

● Special Capabilities

System Development Concepts(Low Level)

System Development Concept

● Host and Target● Host Tools

System Development ConceptsHost and Target

● Host:

A system which is used to develop the target.

● Target:

A system which is being developed for specific application.

System Development ConceptsHost Tools

● Software

– Cross Compiler : XC8 (Free Version)

– Code Down Loader : Tiny Bootloader● Hardware

– None :). Just a PC with DB9 port or an USB to Serial Converter

Understanding Target – RL-eCee-PIC184580

Understanding Target

● RL-eCee-18F4580 Architecture

● RL-eCee-18F4580 Development Board

● Understanding the Target Controller

Understanding TargetRL-eCee-PIC184580 Architecture

PIC18F4580

I2CRTC / EEPROM

LM35Temp Sensor

RS232

GPIO

Digital / MatrixKeypad

LEDsSSDs

CLCD

ADC(Single Port)

CAN

TSOPIR Sensor

Buzzer

ON ChipBootloader

Understanding TargetRL-eCee-PIC184580 Development Board

● PIC18F4580● CLCD● SSD● LEDs● Matrix Keypad● Digital Keypad● RS232● CAN● I2C - EEPROM● I2C - DS1338● Temperature

Sensor● IR Sensor● I/O Extensions

Understanding Target ControllerPIC18F4580

Understanding Target ControllerPIC18F4580

● Architecture

● Program Memory

● Data Memory

● Pin Diagram

● Clocking

● I/O Config

Understanding Target ControllerPIC18F4580 Clocking

Understanding Target ControllerPIC18F4580 I/O Config

Work Environment and DevelopmentGuidelines

Work Environment and Development Guidelines

● Workspace Creation

● Code Structure

● Code Template

● Code Dump Creation

Workspace Creation

Code Structure

Code Template

#ifndef MAIN_H#define MAIN_H

#include <htc.h>

#endif

#include “main.h”

void init_config(void){

/* Initilization Code */}

void main(void){

init_config();

while (1){

/* Application Code */}

}

__CONFIG(DEBUGDIS & LVPDIS & FCMDIS & IESODIS & BORDIS & DUNPROTECT & UNPROTECT & MCLREN & PWRTDIS & WDTDIS & HS );

__CONFIG(WP0 & BORV21);

Code Dump Creation

● Compilation using picc would be$ <path>/xc8 --chip=18f4580 main.c

● Hex code dumping

$ <path>/tinybldlin.py –-port /dev/<device_file> --file pic16f887.hex

Lets Roll Out on Interfaces

Lets Roll Out on Interfaces

● LEDs

● Digital Keypad

● Interrupts

● Timers

● Clock I/O

● Analog Inputs

● SSDs

● CLCD

● Matrix Keypad

● Data Storage

Light Emitting Diodes

LEDsIntroduction

● Simplest device used in most on the embedded applications as feedback

● Works just like diodes

● Low energy consumptions, longer life, smaller size, faster switching make it usable in wide application fields like

– Home lighting,

– Remote Controls, Surveillance,

– Displays and many more!!

LEDsExample

● Which side will work?

LEDsExample

ON

● Oops :( wrong choice. Can you explain why?

LEDsExample – Correct Choice :)

● Ooh :) looks like you know the funda.

LEDsCircuit on Board

Digital Keypad

Digital Keypad

● Introduction

● Interfacing

● Input Detection

● Bouncing Effect

● Circuit on Board

Digital KeypadIntroduction

● Provides simple and cheap interface

● Comes in different shapes and sizes

● Preferable if the no of user inputs are less

● Mostly based on tactile switches

● Some common application of tactile keys are

– HMI

– Mobile Phones

– Computer Mouse etc,.

Digital KeypadTactile Switches Interfacing

● Considering the below design what will be input to the controller if the switch is pressed?

Digital KeypadTactile Switches Interfacing

● Will this solve the problem which may arise in the design mentioned in previous slide?

Digital KeypadTactile Switches Interfacing

● Now will this solve the problem which may arise in the design mentioned in previous slides?

Digital KeypadTactile Switches Interfacing

● What would you call the this design. Is there any potential problem?

Digital KeypadTactile Switches Interfacing

Digital KeypadTriggering Methods

Digital KeypadBouncing Effects

Digital KeypadCircuit on Board

Interrupts

Interrupts

● Basic Concepts

● Interrupt Source

● Interrupt Classification

● Interrupt Handling

● An interrupt is a communication process set up in a microprocessor or microcontroller in which:

– An internal or external device requests the MPU to stop the processing

– The MPU acknowledges the request

– Attends to the request

– Goes back to processing where it was interrupted● Polling

InterruptsBasic Concepts

● Loss of Events

● Response

● Power Management

InterruptsInterrupt vs Polling

● External

● Timers

● Peripherals

InterruptSources

InterruptClassification

InterruptHandling

InterruptService Routine (ISR)

● Similar to a subroutine

● Attends to the request of an interrupting source

– Clears the interrupt flag

– Should save register contents that may be affected by the code in the ISR

– Must be terminated with the instruction RETFIE

● When an interrupt occurs, the MPU:

– Completes the instruction being executed

– Disables global interrupt enable

– Places the address from the program counter on the stack

● Return from interrupt

InterruptService Routine (ISR)

● What / What Not

InterruptLatency

● Latency is determined by:

– Instruction time (how long is the longest)

– How much of the context must be saved

– How much of the context must be restored

– The effort to implement priority scheme

– Time spend executing protected code

bit glow_led;

void interrupt external_pin(void){

if (INTFLAG){

glow_led = 1;INTFLAG = 0;

}}

static void init_config(void){

init_external_interrupt();}

InterruptsExternal Interrupt - Example

void main(void){

init_config();

while (1){

while (!glow_led){

if (SWITCH == 1)

{glow_led =

1;}_asm;

NOP;NOP;NOP;

_endasm}if (glow_led){

LED = 0;}

}}

Timers

TimersIntroduction

● Resolution Register Width

● Tick Up Count or Down Count

● Quantum System Clock settings

● Scaling Pre or Post

● Modes

● Counter● PWM or Pulse Generator● PW or PP Measurement etc.,

● Examples

TimersExample

● Requirement – 5 pulses of 8 µsecs

● Resolution – 8 Bit

● Quantum – 1 µsecs

● General

TimersExample

Clock I/O

Clock I/OIntroduction

● Most peripheral devices depends on Clocking

● Controllers have to generate clock to communicate with the peripherals

● Some of the Controllers internal peripherals work on external clocking provided at it pins

Clock I/OIntroduction

● The activity on the devices could be on

– Edges

– Levels

Clock I/OPWM

● Sometimes called as PDM (Pulse Duration Modulation)

● A technique used to vary the active time vs inactive time in a fixed period.

● Mostly used to control the average voltage of the Load connected.

● Used in wide applications like Motor Controls, Lamp Dimmers, Audio, Power Controls and many more..

Clock I/OPWM

Analog Inputs

Analog InputsIntroduction

● Very important peripheral in embedded systems for real time activities

● Multiplexed with normal GPIO

● Comes with different resolutions

Analog InputsSAR

Seven Segment Displays

SSDIntroduction

● Array of LEDs connected internally

● Possible configurations are common cathode and common anode

● Very good line of sight

● Used in many applications

SSDIntroduction

Segment Data – 10100100 & Control Line - C2Segment Data – 10010010 & Control Line - C3

Let's assume that we are using common anode display

Data map - hgfedcba

Circuit

SSDExample

Segment Data – 10100100 & Control Line - C2

SSDExample

Segment Data – 10010010 & Control Line - C3

SSDExample

SSDExample

SSDExample

SSDExample

SSDCircuit on Board

Character Liquid Crystal Display

CLCDIntroduction

● Most commonly used display ASCII characters

● Some customization in symbols possible

● Communication Modes

– 8 Bit Mode

– 4 Bit Mode

CLCDCircuit on Board

Matrix Keypad

Matrix KeypadIntroduction

● Used when the more number of user inputs is required and still want to save the some controller I/O lines

● Uses rows and columns concept

● Most commonly used in Telephonic, Calculators, Digital lockers and many more applications

Matrix KeypadExample

Data Storage

● Mostly used in every Embedded System

● The size and component (memory) of storage depends upon the requirements

● Modern controllers has built in data storage

– EEPROM

– Data Flash etc.

Data StorageIntroduction

Thank You

top related