Buyer Beware $0.95 Is it worth it? Qualifications Did you ever - - PowerPoint PPT Presentation

buyer beware
SMART_READER_LITE
LIVE PREVIEW

Buyer Beware $0.95 Is it worth it? Qualifications Did you ever - - PowerPoint PPT Presentation

T HE A RDUINO M ICROCONTROLLERS Presented by: Forest Shick, WA2MZG Buyer Beware $0.95 Is it worth it? Qualifications Did you ever wonder Why is this person presenting? I do!! Single Board Computers Asus.com/us/single-board-


slide-1
SLIDE 1

THE ARDUINO MICROCONTROLLERS

Presented by: Forest Shick, WA2MZG

slide-2
SLIDE 2

Buyer Beware

$0.95 Is it worth it?

slide-3
SLIDE 3

Qualifications

Did you ever wonder Why is this person presenting? I do!!

slide-4
SLIDE 4

Single Board Computers

Beagleboard.org Raspberrypi.org Asus.com/us/single-board- computer/tinker-board

slide-5
SLIDE 5

Other Microcomputer Modules

Teensy 3.2 Teensy 3.6 Teensy 4.0 Pjrc.com/teensy/ 3.2 – 72MHz Cortex M4 3.6 – 180MHz Cortex-M4F 4.0 – 600 MHz ARM Cortex M7 NANO – 16MHz 8 bit Arduino NANO

slide-6
SLIDE 6

What is an Arduino?

slide-7
SLIDE 7

Other Arduino Modules

slide-8
SLIDE 8

Arduino Shields

slide-9
SLIDE 9

What is an Arduino good for?

  • Weather station
  • Rotor controller
  • Station 24 Hr Clock
  • Robot
  • Light Controller
  • Simple Security System
  • Homebrew test equipment
  • Game design – remember

Simon?

  • Station control / accessories
  • Keyer
  • Home automation
  • Use your imagination
  • Steppingstone to the

Raspberry Pi and other more powerful devices

  • Having fun
  • Saying – “I DID THAT”!!
slide-10
SLIDE 10

Prototyping

slide-11
SLIDE 11

Projects – Direct Conversion Receiver

NANO controls the LCD and the DDS chip – the VFO in this direct conversion receiver

slide-12
SLIDE 12

Projects

First steps in an SSB transceiver. This uses an UNO.

slide-13
SLIDE 13

Projects – Morse Code Tool

The Arduino MEGA was used because the SD card required a lot of memory space – program and RAM Details are in a previous issue of the RAG

slide-14
SLIDE 14

Let’s Get Started

  • To be fair – there is more relevant material than we can cover in 1 hour
  • We will start with an overview of the NANO
  • We will investigate the more common / easy to use features first
  • Initialization
  • Digital IO
  • Analog Conversion
  • As time permits, we will do a 10,000 ft view of as many features as possible
slide-15
SLIDE 15

Comparison

UNO NANO MEGA Microcontroller ATmega328P ATmega328 ATmega2560 Digital IO 14 22 54 Analog IO 6 8 16 PWM 6 6 15 UART 1 1 4 Flash 32K 32K 256K RAM 2K 2K 8K EEPROM 1K 1K 4K Clock 16MHz 16MHz 16MHZ LED_BUILTIN 13 13 13 Pins 28 32 100

slide-16
SLIDE 16

Microcontroller Block Diagram

ATmega328 ATmega2560

slide-17
SLIDE 17

ATmega328 Data Sheet

There are 294 pages in this data “book” At some level of project complexity many of these pages will be important to your project BUT Arduino has done a great job of getting you started without having to depend

  • n this book.

The Arduino web site has much to offer if you have the time to look through it. TAKE THE TIME NOTE: I have not found a hardware description – it could be there somewhere!

slide-18
SLIDE 18

AVR CPU Core and Sample of Instruction Set

slide-19
SLIDE 19

NANO / ATmega328 Features

  • 32K bytes of Flash memory
  • 1K bytes of EEPROM
  • 2K bytes of RAM
  • Two 8 bit Timer / Counter
  • Prescaler
  • Output Compare
  • One 16 bit Timer / Counter
  • Prescaler
  • Input Capture
  • Output Compare
  • Real time counter and oscillator
  • Six Pulse Width Modulator channels
  • 8 channel, 10 bit A/D
  • Internal temperature measurement
  • USART (UART)
  • SPI
  • I2C / IIC / TWI
  • Watchdog timer and oscillator
  • Analog Comparator
  • Interrupt
  • Pin Change Interrupts
  • 23 Programmable IO lines
slide-20
SLIDE 20

Shared Pin Functionality

As you can see there are only 32 pins, 7 of which are power and ground. Leaving only 25 for all the SHARED hardware functions See the multiple functions for each pin.

slide-21
SLIDE 21

Arduino UNO Schematic

slide-22
SLIDE 22

Arduino MEGA Schematic

slide-23
SLIDE 23

NANO Schematic

slide-24
SLIDE 24

NANO Pin Out

Notice the multiple functions assigned to each pin POWER - red GND - black Discussed on the next slide Be aware of the multiple numbering systems. The VIOLET numbers are the names of the digital IO. The GREEN letter number combination are the analog

  • inputs. The GRAY numbers are the pin number of the microcontroller.
slide-25
SLIDE 25

Powering the NANO

  • For development, when you connect the NANO to

the USB port on your computer, the board is powered from the USB port – shown by the blue circles

  • External power may be applied to the Vin pin, red
  • circle. It is then regulated to 5V to power the

board and accessories

  • 5 volt power, violet circle, may also be applied to

the 5V pin to power the board and accessories

  • The 3.3V pin, light blue is NOT power input. It is

power output not to exceed 50ma.

slide-26
SLIDE 26

NANO Pin Functions

slide-27
SLIDE 27

Arduino NANO Conclusion

slide-28
SLIDE 28

Initial Conditions

  • Most pins are tri-state during reset
  • Many registers provide the initial

condition of the pins

  • Properly terminate unused pins
  • DDR – 0 = Input and 1 = Output
  • WHY?
slide-29
SLIDE 29

Digital IO – Chapter 13

  • Circles
  • RED – pull up resistor
  • BLUE – output
  • GREEN - input
  • Squares
  • RED – Pull up disable signal
  • BLUE – reads the state of the

port output

  • GREEN – reads the state of

the port input

  • NOTE – the port output and

port input may not be the same Each of the 14 digital pins on the Nano can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions

slide-30
SLIDE 30

Digital IO

Registers

  • DDxn – Data Direction, Port x, Bit n
  • PORTxn – Data output port
  • PINxn – Data input port
  • pinMode(pin, mode)
  • pin 0 – 22 (D0 - D22)
  • mode: INPUT, OUTPUT, INPUT_PULLUP
  • digitalRead(pin)
  • Returns the state of the pin
  • digitalWrite(pin, value)
  • Value – write a 0 or 1 to the pin

pinMode(8, OUTPUT); // Make D8 an output In C DDRB = (1<< DDB0); // Set DDRB0 to 1 (output) digitalWrite(8, 1); // set D8 to 1 In C PORTB = (1 << PB0); // set PORTB0 to 1

slide-31
SLIDE 31

Digital IO Examples

Turn a LED on and off Read a push button switch Drive and read a 4 x 4 keypad pinMode(8, OUTPUT); digitalWrite(8, 1); pinMode(5, INPUT_PULLUP); sw = digitalRead(5);

pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, INPUT_PULLUP); pinMode(9, INPUT_PULLUP); pinMode(10, INPUT_PULLUP); pinMode(11, INPUT_PULLUP); PORTD = 0xf0; val = PINB & 0x0f;

slide-32
SLIDE 32

A/D Converter Inputs – Chap 23

The Nano has 8 analog inputs, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though it is possible to change the upper end of their range using the analogReference() function. Analog pins 6 and 7 cannot be used as digital

  • pins. Additionally, some pins have specialized,

alternate functionality: I2C: A4 (SDA) and A5 (SCL). Support I2C (TWI) communication Analog Input Resistance: 100M ohms Reference Input Resistance: 23k ohms

slide-33
SLIDE 33

A/D Converter

  • analogReference(type)
  • DEFAULT – 5V power
  • INTERNAL – 1.1V
  • EXTERNAL – voltage on the AREF pin
  • analogRead(pin)
  • A0 – A7 (ADC0 – ADC7)

analogReference(DEFAULT); // optional . . int value; . . // Measure the voltage on ADC1 value = analogRead(A1);

slide-34
SLIDE 34

A/D Converter

Reading a potentiometer Reading a temperature sensor int val; val = analogRead(A0); int val; analogReference(EXTERNAL); val = analogRead(A6);

slide-35
SLIDE 35

Alternate Port Functions

  • Clock oscillator
  • Timer Oscillator
  • Pin change interrupt
  • SPI
  • Output Compare
  • Input capture
  • Reset
  • A/D Converter
  • IIC / I2C / TWI
  • Analog Comparator
  • USART
  • External clock
  • External Interrupt
slide-36
SLIDE 36

Analog Comparator – Chap 22

The Analog Comparator compares the input values on the positive pin AIN0 and negative pin AIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator output, ACO, is set. The comparator’s output can be set to trigger the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate interrupt, exclusive to the Analog

  • Comparator. The user can select

Interrupt triggering on comparator

  • utput rise, fall or toggle.

Uses

  • Period / frequency measurement
  • Voltage threshold
  • Phase measurement
slide-37
SLIDE 37

Communications

USART – Chap 19

  • Full duplex
  • Baud rate generator
  • 5 – 9 data bit and 1 or 2 stop bits
  • More
  • The NANO and UNO only have 1
  • It is assigned to the USB comms
  • D0 – RX
  • D1 - TX

SPI – Serial Peripheral Interface – Chap 18

  • Full duplex
  • Master or slave
  • 7 programmable bit rates
  • MISO – D12 – Master in / Slave out
  • MOSI – D11 – Master Out / Slave in
  • SCK – D13 – Serial Clock
  • SS – D10 – Slave Select
  • Use the SPI library

TWI – 2 wire Serial Interface – Chap 21

  • Also known as IIC & I2C
  • SCL – A5
  • SDA – A4
  • Use the Wire library
slide-38
SLIDE 38

8 Bit Timer / Counter – Chap 14 & 17

  • There are 2, 8 bit timer / counters
  • Output Compare
  • PWM
  • Frequency Generation

OUTPUT COMPARE

  • A value can be set in the OC register
  • When the counter reaches that value

a port pin will change state PULSE WIDTH MODULATOR

  • Creates a repetitive waveform with a

duty cycle set by an 8 bit word

slide-39
SLIDE 39

16 Bit Timer / Counter – Chap 15

  • One 16 bit timer counters
  • Output Compare
  • Input Capture
  • PWM
  • Frequency generation
  • Event counting
slide-40
SLIDE 40

Interrupts – Chap 11

There are 26 sources of interrupts What is an interrupt?

  • An interrupt changes the normal flow of a

program.

  • An interrupt is usually caused by an asynchronous

process that requires attention

  • When an interrupt occurs, the current instruction is

completed and control jumps to a special interrupt routine

  • When the interrupt routine is complete, the next

instruction, in the main program, is executed

  • The only interrupt that you have no control over is

RESET

  • All other interrupts may be enabled or disabled
  • All interrupts are disabled at reset
slide-41
SLIDE 41

External Interrupts – Chap 12

  • External interrupts are triggered from a source outside of the

microcontroller

  • There are 2 external interrupts, INT0 & INT1, which are

addressed using the IDE functions

  • External interrupts can be triggered by:
  • Low level
  • Logic change
  • Falling edge
  • Rising edge
  • There are 23 pin change interrupts that the IDE functions DO

NOT handle : PCINT0 to PCINT23 (No PCINT15)

  • Pin change interrupts are triggered by:
  • Rising and falling edges
  • You don’t get to pick which one
slide-42
SLIDE 42

Internal Interrupts

The internal interrupts are triggered by actions of the internal peripherals – although external stimulus may be involved – receiving data on the TWI – the interrupt occurs because 8 data bits were transferred on the TWI lines There are 20 internal interrupts Beyond the scope of our discussion today They are extremely useful but require studying the appropriate sections of the manual.

slide-43
SLIDE 43

Timer / Counter and Pin Change Interrupt Example

  • D14 & 15 Use PCINT to detect key

down and up – triggering a timer for dot and dash length

  • D11 & 12 use PCINT to detect

rotation of the rotary encoder and direction

  • A11 uses PCINT to detection

pushbutton action

  • A8 uses a timer for tone generation
  • A10 use PCINT and a timer to

detect and decode incoming Morse code

  • TWI is used to communicate with

the LCD

  • SPI is used to read and write the SD

Card

slide-44
SLIDE 44

Resources

  • Information & pictures are taken from the following:
  • Arduino web site
  • ATmega data sheet
  • Various advertiser in a Google search
  • Adafruit