Making the most of the Value Line MSP430 with

advertisement
Making the most of the Value Line
MSP430 with the LaunchPad
Explorer
Nov 17, 2015
Simply Embedded
Chris Karaplis & Kevin Strom
1
Overview
• Who we are and what is Simply Embedded
• Value Line MSP430 and Launchpad ecosystem
• LaunchPad Explorer: what is it and why did we make it
• System overview / block diagram
• Clock and timer configuration
• Controlling 2 dual 7-segment displays using two shift registers
• I2C/SPI with a single USCI_B module
• ADC10 with analog front end
• PWM based signal generator
• General software and hardware considerations
• Conclusion
• Future improvements / possible features
• Q&A
2
Who we are and what is Simply Embedded
• Simply Embedded was founded in August 2014 as a free resource to help
people learn about embedded programming
• Many frameworks and environments have been developed to make embedded
development easier but frequency at the cost of abstraction from the hardware
• Simply Embedded’s tutorials are designed to a more complete picture
• Chris: embedded software engineer
– BSc EE, but began in industry as software designer with 5 years in industry
– Experience in avionic communications, consumer electronics and cellular
telecommunication equipment
• Kevin: digital hardware engineer
– BSc EE, 15 years in industry
– Digital and Embedded hardware development in Network and
Telecommunications, Medical/Consumer, and Industrial segments
3
MSP430 and LaunchPad ecosystem
• The MSP430 is a 16-bit microcontroller
• Low cost, low power but high value
• Used in many different devices in a wide range of industries
• Mature product: been on the market for years
• Line up has been expanded over the years to include higher end
MSP430s and other devices
• The LaunchPad ecosystem started with the MSP-EXP430G2
• Great for development and evaluation because they provide an onboard programmer and debugger
• Built to support BoosterPacks developed by TI and Third Parties (like
us!)
4
LaunchPad Explorer:
What is it and why did we make it
5
LaunchPad Explorer:
What is it and why did we make it
• The LaunchPad Explorer is a BoosterPack we developed to teach
embedded system design
• Compliments our free online tutorials
• Hardware and software will be open source
• Has everything you need to learn the basics and explore the majority of
peripherals on the MSP430G2553
• Intended to be useful even after you have completed the tutorials
• Currently at the prototype stage with plans for availability in Q2 of 2016
• Project will be crowd funded end of 2015
6
System Overview
7
Clock and Timer Configuration
• 8MHz MCLK sourced from DCO
– Using TLV calibration tables
• 4MHz SMCLK sourced from DCO (divided by 2)
– Clock source for most peripherals
• AUXCLK sourced by VLO
– Only used for watchdog
• TimerA0 used by a custom timer library
• TimerA1 used for PWM based signal generator
8
7-Segment Display Control
• MSP430G2553 is only a 20 pin device, insufficient I/O to drive display
directly (16 signals to drive two dual displays)
• A shift register is a convenient way reduce the pin requirements on the
microcontroller while maintaining higher speed than an general I/O
expander
• For LPEx the shift register is driven by a subset of the SPI interface
lines, SCLK, MOSI, and CS#
9
7-Segment Display Control
• SPI driver initializes the USCI_B peripheral as SPI master
• Speed set to 400kHz, SPI mode CPOL = 0, CPHA = 1
• CS manually toggled via GPIO
• The display function is contained in a library which controls all SPI
transactions, the digital control via GPIO, and the display refresh rate
• Scaled integer is passed to driver with scaling factor
• Convert to 4-bit BCD
• Character map for each dual 7-segment display
• Refresh is every 75ms (rate of ~13Hz), fast enough for POV to provide
no flicker
10
7-Segment Display Control
11
I2C and SPI via the USCI_B module
• USCI_B is the only peripheral available for general use
• Support for both I2C and SPI required
– I2C devices: temperature sensor, EEPROM & IO expanders
– SPI devices: dual 7 segment display & SPI NOR
• Solution: drive I2C and SPI using a single USCI_B module
• Hardware switch to isolate I2C devices
• In I2C mode, SPI devices don’t respond because their chip select is not
asserted
• In SPI mode, I2C bus is disconnected from USCI_B
• Drivers responsible for controlling the switch and configuring USCI_B
• Use the open/close model to control access to the peripheral
12
LPEx Block Diagram
13
I2C and SPI via the USCI_B module
See video in webinar recording.
14
ADC10 with Analog Front End
• The internal ADC can be directly fed with a voltage to measured
• Many applications require amplification or other signal conditioning
• LPEx provides two input conditioning channels with gains of
2,11,101,1001 (Hardware Hackable)
• Each AFE is configured as a dual op-amp Instrumentation Amplifier
to provide for large gain and high input impedance
• Each AFE also includes a calibration feature to account for
component tolerances and op-amp non-idealities
• Each channel can be generally used or as a unique function
– Resistance Measurement
– Temperature Measurement via thermocouple
– These features provide for experimentation
15
ADC10 with Analog Front End
•
•
•
•
•
•
•
•
•
ADC clock is sourced by SMCLK / 8 = 500kHz (period of 2us)
Sample time: 64 clock cycles = 128us
Sync time for ADC: 1clk = 2us
Conversion time: 13 * 2us = 26us
Total conversion time = 156us
Sampling rate of ~6.5ksps
Using internal 2.5V reference generator
Value calculated using ADC calibration data in Information Memory
Considerations for dealing with component issues
16
ADC10 with Analog Front End
See video in webinar recording
17
PWM based Signal Generator
•ADCs in microcontrollers are easy, they’re typically built-in
•How can we make a DAC though?
•External SPI or I2C DACs are available, but are may be costly
•The poor man’s solution is a filtered PWM signal
•LPEx provides two PWM channels, one dedicated to the current
source, and one for general DAC output
•General DAC filter is a low pass filter with a rough 6kHz BW
•Configurable (HW) op-amp output stage for gain on General DAC
18
PWM based Signal Generator
•PWM generated using TIMER_A
•Two timer blocks must be used - frequency & duty cycle
•At expiration of the first timer block, the output it toggled high
•At expiration of the second timer block the output is driven low
•For simple PWM, once configuration is set, rest is taken care of in HW
•In case of sine wave, duty cycle needs to be variable
•Precomputed table of duty cycles - 21 points - half of the sine wave
•Interrupt is enabled for second timer block
•Upon each expiry, the duty cycle is changes based on the next value in
the table
19
PWM based Signal Generator
See video in webinar recording
20
General software considerations
• MSP430G2553 has limited memory (16kB flash, 512 bytes RAM)
• No hardware multiplier - math can be expensive
• No floating point calculations
– Using scaled integers where required
• Design of each module has to be carefully designed for the best
balance between speed and memory
– ex: using a lookup table for the function generator vs. calculations
• Event queues are much more effective than a super loop
– Timer library generates interrupt
– Interrupt invokes callback
– Callback sends an event
– Main event loop processes the event
• There is still room for optimization
– Compiler optimizations are off
– Some ‘easy’ software optimizations, but not much research or
effort to find the best way for this prototype
21
General hardware considerations
• Many applications employing low cost microcontollers are cost
sensitive
• A balance between hardware and software trade-offs must be found
• Pin count and I/O usage
– Rely on peripheral busses to allow I/O expansion
– Multi-use of USCI_B to get a greater value from the microcontroller
• Balance to provide enough calibration flexibility to AFEs without
overloading the software requirements
22
Conclusion
• Cost effective designs can be achieved when hardware and software
decisions are made in concert
• Development of the LPEx continuously considers the strengths and
weaknesses in both the circuit design and firmware design arenas
• Development effort for all sides needs to be considered, it is
tempting to say, sometimes, ‘we can just deal with it in software’, but
resource limited microcontrollers may not permit such a cavalier
attitude
• Did we make the most of the MSP430G2553? Yes!
– Things we didn’t cover:
• capacitive touch sense
• IrDA
• Low power mode
23
Future improvements
• Extra filter stage on PWM
• Positions on AFEs for filtering components
• Pre-divider on at least one AFE input to allow higher voltages to be
measured
• Store waveforms in flash memory controller and load at runtime
• EEPROM for ADC calibration
• General purpose GPIO expander library
24
Thank you!
simplyembedded.org
25
Q&A
26
Download