55:036 Embedded Systems and Systems...
Transcript of 55:036 Embedded Systems and Systems...
Lecture 2-4, Slide 1 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Embedded Systems and Software
Embedded Systems in Vehicles
Notes on Lab 2
Lecture 2-4, Slide 2 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Lab 02
Pushbutton Switch
ATtiny45
LED Driver
In this lab students implement an interval timer using a pushbutton switch, ATtiny45, an LED driver, and two seven-segment displays
When the user presses the button, the microcontroller start counting from 0 to 9.9 in 100 ms intervals. When the user presses the button again, the counter stops.
If there is an overflow (user wait longer than 9.9 s), the display should show “9.9” and flash once per second.
Lecture 2-4, Slide 3 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Seven Segment Displays
Each of the seven segments and the decimal point is a LED
Segments
By turning a subset of the LEDs on, one can display the numbers 0 – 9 and some letters as well
Decimal Point
These displays are sold in single- or multiple character units. They come in all shapes and sizes
Other variations include multiple decimal points, colons, + and – signs etc.
Lecture 2-4, Slide 4 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Common Anode, Common Cathode
Most of these displays connect either all the cathodes or all the anodes together.
They are called Common Anode or Common Cathode displays
Each segments and the decimal point is an LED
Lecture 2-4, Slide 5 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Driving a Seven Segment Display
Common Anode
Pulling a line low turns the corresponding segment on
Lecture 2-4, Slide 6 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Driving a Seven Segment Display
Common Anode
Lecture 2-4, Slide 7 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Driving a Seven Segment Display
Common Anode
Lecture 2-4, Slide 8 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Driving a Seven Segment Display
Common Anode
Turn on multiple LEDs to create the desired number
Lecture 2-4, Slide 9 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Issues #1 – Too manly Lines
Common Anode
Turn on multiple LEDs to create the desired number
To drive the display directly from a microcontroller means we need 8 lines per seven segment module
This will quickly deplete the number I/O pins on a microcontroller
Lecture 2-4, Slide 10 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Issues #2 –LED Temperature and Aging Effects
Common Anode
An LED’s forward bias voltage is a function of ambient temperature
With resistors, this means the current and therefore the brightness depends on temperature
Lecture 2-4, Slide 11 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
LED Driver ICs
To address the issues with the simplistic driving of displays and LEDs in general, several companies market special LED drivers ICs.
A bit pattern is shifted in on the
DATA line
SDI
Control lines latch the data and turn on the
current sources
The data is also shifted out so that one can put several IC in series
Current sources/sinks ensure LED current does not change with temperature
CLK
OE
Lecture 2-4, Slide 12 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Adding More Displays
SDI
CLK
OE1
SDI
CLK
OE2
To add another display, we need just one more line
In operation, shift the desired 16-bit pattern in, and turn on the drivers. We control individual modules with their Output Enable (OE) lines
Lecture 2-4, Slide 13 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Adding More Displays - Alternative Method
SDI
CLK
OE1
SDI
CLK
OE2
All displays use the same control lines
In operation, shift the desired 16-bit pattern in, and turn on the drivers. We control individual modules with by shifting in the proper bit pattern
Lecture 2-4, Slide 14 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
The TLC5916IN LED Driver Overview To use the IC successfully, you have to read the data sheet. In the next few slides we give an overview.
Lecture 2-4, Slide 15 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
The TLC5916IN LED Driver Overview
TLC5916IN
Serial Data In
Latch Enable
Clock
~OE
Serial Data Out
𝐼𝐼𝑂𝑂𝑂𝑂𝑂𝑂 = 151.25𝑅𝑅𝐸𝐸𝐸𝐸𝑂𝑂
𝑉𝑉𝐶𝐶𝐶𝐶 (5 V)
This notation is the same as OE
𝑽𝑽𝑪𝑪𝑪𝑪
Lecture 2-4, Slide 16 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Notation
A bar above a pin means that the pin is active low
For an output pin, then means the pin will be pulled low when it is activated
For an input pin, it means it must be pulled to perform its function
LEDs turn on when output pins are pulled low
Output drivers are turned on when OE is pulled low
Sometimes this is written as ~OE
𝑽𝑽𝑪𝑪𝑪𝑪
Lecture 2-4, Slide 17 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Cascading TLC5916IN LED
For this lab, cascade two drivers is this fashion. This means you will need 4 output lines and 1 input line.
Design 𝑅𝑅 for 10 mA
Lecture 2-4, Slide 18 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
The LDS-A514RI Display
Pin 5 Pin1 Pin 5
Pin 10
Pin1
Pin 6 Pin 10
Lecture 2-4, Slide 19 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
The LDS-A514RI Display
Mapping from pin numbers to segments
Lecture 2-4, Slide 20 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
The LDS-A514RI Display
Be sure not to exceed maximum ratings. For the lab, design the LED driver so that each segment gets 10 mA
Lecture 2-4, Slide 21 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Assigning ATtiny45 Pins
These are used by the ISP programmer when it downloads code
𝑉𝑉𝐶𝐶𝐶𝐶 (5 V) Reset Line
We need 4 control lines and one input line. However, here is the status of the development board:
Seems like we don’t have enough pins. This is a typical constraint in embedded systems
The game plan is to disable disconnect the crystal and that frees up two pins. If we are careful, we can also use the ISP lines.
Question - what is ISP?
Lecture 2-4, Slide 22 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Use ATtiny45’s Internal RC Oscillator
These jumpers connect the crystal to the microcontroller
We want to use the internal RC oscillator so that can use PB3 and PB4 for controlling the LED drivers
Thus, we must first configure the Attiny45 to use the internal oscillator and then remove these jumpers.
If you remove the jumpers first then ATtiny45 has no clock and will not run…
Lecture 2-4, Slide 23 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Microcontroller Configuration/Fuses
Set this to the internal RC oscillator
Lecture 2-4, Slide 24 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Using the ISP Lines
These are used by the ISP programmer when it downloads code
𝑉𝑉𝐶𝐶𝐶𝐶 (5 V) Reset Line
𝑉𝑉𝐶𝐶𝐶𝐶 (5 V) Reset Line
Insert 4.7K resistors to avoid your hardware conflicts with programming. Note that this may not be needed if the pins are uses as output only.
Lecture 2-4, Slide 25 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Testing Status of an I/O PIN
... cbi DDRB,3 ; Make PB3 input chk: sbis PINB,3 ; See if PB3 is set (high) rjmp down ; No, PB3 is low => switch down => continue rjmp chk ; Yes, PB3 is high, wait some more down: ...
This instruction tests a single bit in an I/O register and skips the next instruction if the bit is set.
𝑉𝑉𝐶𝐶𝐶𝐶 (5 V)
Pullup resistor. Value not critical, 4.7K 100K
Lecture 2-4, Slide 26 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Testing Status of an I/O PIN
... cbi DDRB,3 ... sbis PINB,3 ...
For input use PINB, not PORTB
... cbi DDRB,3 ... sbic PINB,3 ...
Also, there is a companion instruction SBIC (Skip next instruction if bit in I/O is Clear)
You could use either SBIS or SBIC in a loop to test if the pushbutton switch has been pressed
𝑉𝑉𝐶𝐶𝐶𝐶 (5 V)
Lecture 2-4, Slide 27 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Switch Bounce and Debouncing
Bounce
~ 5 ms
Lecture 2-4, Slide 28 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Switch Bounce and Debouncing
t
Volta
ge
Question: what is the fall time? Make sure you can calculate this.
When the switch closes, the capacitor discharges through Rb
Lecture 2-4, Slide 29 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Software Debounce
char isPressed(void) { char ones=0, zeroes=0, i; for(i=0;i<=10-1;i++){ if(PINA&0x01){ // read pin == 1 ones++; } else { // read pin == 0 zeroes++; } _delay_ms(10); } return (ones > zeroes); }
One idea. Sample n times at regular intervals, say 10 ms apart. Count how many times the switch is zero . In this is larger than the number of times the switch is high, consider the switch pressed.
We will use software debounce later in the course. For now, use hardware debounce
Lecture 2-4, Slide 30 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Which PIN to Use?
These are used by the programmer when it downloads code, so adding a debounce capacitor may interfere. You may have to experiment which PIN works best as an input pin. Consider using PB3 for the pushbutton switch.
There are 3 available PINs for use as switch input: PINB0, PINB1, PINB2. Which one should you use?
Lecture 2-4, Slide 31 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
Diagram extracted from TLC5916 data sheet
LEDs turn on when output pins are pulled low
Lecture 2-4, Slide 32 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
Hold OE (drivers are off)
Lecture 2-4, Slide 33 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
Hold OE (drivers are off)
Latch Enable (LE) is low
Lecture 2-4, Slide 34 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
1 0 1 1 1 0 0 1
Hold OE (drivers are off)
Latch Enable (LE) is low
Place bit on SDI line
Make CLK go low high to clock data in
Lecture 2-4, Slide 35 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
1 0 1 1 1 0 0 1
Hold OE (drivers are off)
Latch Enable (LE) is low
Place bit on SDI line
Make CLK go low high to clock data in
Once the number of bits are clocked in, pulse LE
Latch data
Lecture 2-4, Slide 36 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
1 0 1 1 1 0 0 1
Hold OE (drivers are off)
Latch Enable (LE) is low
Finally, pull OE low. While OE is low output drivers are on and LEDs light up
Place bit on SDI line
Make CLK go low high to clock data in
Once the number of bits are clocked in, pulse LE
~OE
Lecture 2-4, Slide 37 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
Hold OE (drivers are off)
Latch Enable (LE) is low
Finally, pull OE low. While OE is low output drivers are on and LEDs light up
Place bit on SDI line
Make CLK go low high to clock data in
Once the number of bits are clocked in, pulse LE
1 0 1 1 1 0 0 1
1
0
1
1
Lecture 2-4, Slide 38 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
More on TLC5916 Operation
1 0 1 1 1 0 0 1
1
0
1
1
Diagram extracted from TLC5916 data sheet
Latch data
~OE
LEDs turn on when output pins are pulled low
Lecture 2-4, Slide 39 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Timing diagram from data sheet
With a 8-MHz clock, a clock cycle is
125 ns
Lecture 2-4, Slide 40 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
𝑡𝑡𝑊𝑊 CLK Clock Pulse Duration (𝑡𝑡𝑤𝑤 CLK )
𝑡𝑡𝑊𝑊 CLK < 1 clock @ 8 MHz
Lecture 2-4, Slide 41 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
𝑡𝑡𝑊𝑊 CLK
𝑡𝑡𝑆𝑆𝑂𝑂 D
SDI Setup Time (𝑡𝑡𝑠𝑠𝑠𝑠 D )
𝑡𝑡𝑠𝑠𝑠𝑠 D < 1 clock @ 8 MHz
Lecture 2-4, Slide 42 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
𝑡𝑡𝑊𝑊 CLK
𝑡𝑡ℎ D
SDI Hold Time (𝑡𝑡ℎ D )
𝑡𝑡ℎ D < 1 clock @ 8 MHz
Lecture 2-4, Slide 43 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
𝑡𝑡ℎ D
~OE Pulse Width (𝑡𝑡𝑊𝑊 OE )
𝒕𝒕𝒘𝒘 𝐎𝐎𝐎𝐎 > 1 clock @ 8 MHz
𝑡𝑡𝑊𝑊 OE
Lecture 2-4, Slide 44 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger
Note that, in general, timing values depend on power supply values, and often on temperature as well
Lecture 2-4, Slide 45 Embedded Systems and Software, ECE:3360. The University of Iowa, 2016 A. Kruger