CS194-126, Software De ned PCBs
Transcript of CS194-126, Software De ned PCBs
CS194-126, Software Defined PCBsLecture 14: Embedded Debugging: System Bring-up
Richard ”Ducky” Lin
11 October 2016
1 Introduction
2 Demonstration
3 Summary
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 1 / 16
Introduction
Introduction
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 2 / 16
Introduction
Goals
So, you have a great idea, and you just finished assembling your hardware.What now?
I Obviously, write firmware
But how to write it efficiently and well?I Efficiently writing code: write and test in small pieces
I If something breaks, narrow down culprits easilyI Make sure fundamentals are sane before building on top
I Writing good code: Thursday!
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 3 / 16
Introduction
Goals
So, you have a great idea, and you just finished assembling your hardware.What now?
I Obviously, write firmware
But how to write it efficiently and well?
I Efficiently writing code: write and test in small piecesI If something breaks, narrow down culprits easilyI Make sure fundamentals are sane before building on top
I Writing good code: Thursday!
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 3 / 16
Introduction
Goals
So, you have a great idea, and you just finished assembling your hardware.What now?
I Obviously, write firmware
But how to write it efficiently and well?I Efficiently writing code: write and test in small pieces
I If something breaks, narrow down culprits easilyI Make sure fundamentals are sane before building on top
I Writing good code: Thursday!
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 3 / 16
Introduction
Platform Introduction no demo like a live demo
EECS192 course project: line-following robot car
I Optical linescan camera, servo actuated steering
I Compute and control handled by microcontroller
I Lots of non-standard peripherals to bring up
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 4 / 16
Introduction
Platform Introduction no demo like a live demo
What would be a logical way to bring up this system?
I Write hardware drivers (encoder, camera, ...)
I Debug hardware drivers, in combination with hardware
I Write application logic (line detect, control loops, ...)
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 4 / 16
Introduction
Platform Introduction no demo like a live demo
What would be a logical way to bring up this system?
I Write hardware drivers (encoder, camera, ...)
I Debug hardware drivers, in combination with hardware
I Write application logic (line detect, control loops, ...)
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 4 / 16
Demonstration
Sanity Check
What’s the first thing we should bring up?
Basic system test and debugging tools
I Classic embedded ”hello, world”: blinkingLEDs
I printf serial console
#include "mbed.h"
RawSerial serial(USBTX
, USBRX);
DigitalOut Led1(PTC8);
DigitalOut Led2(PTD0);
...
int main() {
}
you start here
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 5 / 16
Demonstration
Sanity Check
What’s the first thing we should bring up?
Basic system test and debugging tools
I Classic embedded ”hello, world”: blinkingLEDs
I printf serial console
#include "mbed.h"
RawSerial serial(USBTX
, USBRX);
DigitalOut Led1(PTC8);
DigitalOut Led2(PTD0);
...
int main() {
}
you start here
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 5 / 16
Demonstration
Sanity Check
What’s the first thing we should bring up?
Basic system test and debugging tools
I Classic embedded ”hello, world”: blinkingLEDs
I printf serial console
#include "mbed.h"
RawSerial serial(USBTX
, USBRX);
DigitalOut Led1(PTC8);
DigitalOut Led2(PTD0);
...
int main() {
}
you start here
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 5 / 16
Demonstration
Demonstration
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 6 / 16
Demonstration
Quad Encoder
A quad encoder uses two digital linesto count pulses with directionality(very common device)
How should we code this up?
I Find a library online, don’treinvent the wheel without a good reason
I Someone else has written it, andmany more people have tested it
mbed QEI API
Quad encoder waveforms
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 7 / 16
Demonstration
Quad Encoder
A quad encoder uses two digital linesto count pulses with directionality(very common device)
How should we code this up?
I Find a library online, don’treinvent the wheel without a good reason
I Someone else has written it, andmany more people have tested it
mbed QEI API
Quad encoder waveforms
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 7 / 16
Demonstration
Make the clicky knob work!
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 8 / 16
Demonstration
Now bring up the servo!
you’ve already learned the servo PWM protocol
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 9 / 16
Demonstration
Line Camera
Many peripherals use standardinterfaces, like I2C and SPI
Some don’t, like this line camera
I Generally simple protocols
I Datasheet gives all the details
I Control integration time
I Pixel intensity on analog line
I Clock signal shifts out next pixel
TSL1401 Datasheet, page 5
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 10 / 16
Demonstration
Let’s write some code!
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 11 / 16
Demonstration
External ADC
A thermistor is connected to anexternal ADC, connected by I2C
So let’s bring up the ADC
I Datasheet describes protocol interms of I2C transactions
I Basically: write configurationregisters, read conversion result
ADS1015 Datasheet, page 8
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 12 / 16
Demonstration
I2C Fun Time!
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 13 / 16
Demonstration
Thermistors
MCP9701 is a linear activethermistor
I Voltage is proportional totemperature
I Details (offset and scaleconstants) in datasheet
I Around 20C, what is theexpected voltage?
I 0.8 V
I How would you code up theconversion from voltage totemperature?
MCP9701 Datasheet, pages 3 and 7
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 14 / 16
Demonstration
Thermistors
MCP9701 is a linear activethermistor
I Voltage is proportional totemperature
I Details (offset and scaleconstants) in datasheet
I Around 20C, what is theexpected voltage?
I 0.8 V
I How would you code up theconversion from voltage totemperature?
MCP9701 Datasheet, pages 3 and 7
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 14 / 16
Demonstration
Thermistors
MCP9701 is a linear activethermistor
I Voltage is proportional totemperature
I Details (offset and scaleconstants) in datasheet
I Around 20C, what is theexpected voltage?
I 0.8 V
I How would you code up theconversion from voltage totemperature?
MCP9701 Datasheet, pages 3 and 7
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 14 / 16
Demonstration
Closed-loop tracking fun demo
Bringing it all together
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 15 / 16
Summary
Summary
I Whirlwind tour of embedded system bring-up with custom peripheralsI A lot of artificial failures as examples of common failure modesI ... and a lot of details glossed over
I Write code incrementallyI Less things added, less things to question if something goes wrongI Verify each part before building on top of it
I When stuff goes wrong, get visibility into the systemI printf for software visibilityI Multimeter for non-time-varying quantities, like power railsI Oscilloscope for analog signalsI Logic analyzer for digital signals, with protocol analyzers
I Design for TestI Make system visibility easy, like with probe points
Ducky (UCB EECS) Embedded Debugging: System Bring-up 11 October 2016 16 / 16