Renesas Electronics America Inc. © 2010 Renesas Electronics America Inc. All rights reserved. A30L: Increase the Dynamic Range and Precision of Digital Filters by using an MCU’s FPU Kevin P King Senior Staff Applications Engineer 14 October 2010 Version 1.1
2 © 2010 Renesas Electronics America Inc. All rights reserved. Kevin P King Education Electrical Engineering, University of Lowell (Edward B Van Dusen Award for Academic Achievement) Thirty years of Embedded Design Experience (x86, HC05, HC11, 8051, Philips XA, Atmel AVR, Hitachi, Mitsubishi, etc.... Five years of Emulator design for MetaLink COP8, 68HC05, 68HC11, 8051 (multi-vendors), National CR16, Hitachi H8/500, etc... Multiple Quality Awards for Embedded Software & Hardware Development. Specialty is Embedded System Design - MCU firmware & hardware Senior Staff Application Engineer Primary Tech Support for SH2A Focusing on Medical Segment and SH Family
3 © 2010 Renesas Electronics America Inc. All rights reserved. Renesas Technology and Solution Portfolio Microcontrollers & Microprocessors #1 Market share worldwide * Analog and Power Devices #1 Market share in low-voltage MOSFET** Solutions for Innovation ASIC, ASSP & Memory Advanced and proven technologies * MCU: 31% revenue basis from Gartner "Semiconductor Applications Worldwide Annual Market Share: Database" 25 March 2010 **Power MOSFET: 17.1% on unit basis from Marketing Eye 2009 (17.1% on unit basis).
4 © 2010 Renesas Electronics America Inc. All rights reserved. 4 Renesas Technology and Solution Portfolio Microcontrollers & Microprocessors #1 Market share worldwide * Analog and Power Devices #1 Market share in low-voltage MOSFET** ASIC, ASSP & Memory Advanced and proven technologies * MCU: 31% revenue basis from Gartner "Semiconductor Applications Worldwide Annual Market Share: Database" 25 March 2010 **Power MOSFET: 17.1% on unit basis from Marketing Eye 2009 (17.1% on unit basis). Solutions for Innovation
5 © 2010 Renesas Electronics America Inc. All rights reserved. 5 Microcontroller and Microprocessor Line-up Superscalar, MMU, Multimedia Up to 1200 DMIPS, 45, 65 & 90nm process Video and audio processing on Linux Server, Industrial & Automotive Up to 500 DMIPS, 150 & 90nm process 600uA/MHz, 1.5 uA standby Medical, Automotive & Industrial Legacy Cores Next-generation migration to RX High Performance CPU, FPU, DSC Embedded Security Up to 10 DMIPS, 130nm process 350 uA/MHz, 1uA standby Capacitive touch Up to 25 DMIPS, 150nm process 190 uA/MHz, 0.3uA standby Application-specific integration Up to 25 DMIPS, 180, 90nm process 1mA/MHz, 100uA standby Crypto engine, Hardware security Up to 165 DMIPS, 90nm process 500uA/MHz, 2.5 uA standby Ethernet, CAN, USB, Motor Control, TFT Display High Performance CPU, Low Power Ultra Low Power General Purpose
6 © 2010 Renesas Electronics America Inc. All rights reserved. 6 Microcontroller and Microprocessor Line-up Superscalar, MMU, Multimedia Up to 1200 DMIPS, 45, 65 & 90nm process Video and audio processing on Linux Server, Industrial & Automotive Up to 500 DMIPS, 150 & 90nm process 600uA/MHz, 1.5 uA standby Medical, Automotive & Industrial Legacy Cores Next-generation migration to RX High Performance CPU, FPU, DSC Embedded Security Up to 10 DMIPS, 130nm process 350 uA/MHz, 1uA standby Capacitive touch Up to 25 DMIPS, 150nm process 190 uA/MHz, 0.3uA standby Application-specific integration Up to 25 DMIPS, 180, 90nm process 1mA/MHz, 100uA standby Crypto engine, Hardware security Up to 165 DMIPS, 90nm process 500uA/MHz, 2.5 uA standby Ethernet, CAN, USB, Motor Control, TFT Display High Performance CPU, Low Power Ultra Low Power General Purpose SuperH
7 © 2010 Renesas Electronics America Inc. All rights reserved. Innovation Arc Fault Circuit Interrupter AED
8 © 2010 Renesas Electronics America Inc. All rights reserved. Position Renesas provides you with a selection of cost effective MCUs with hardware Floating Point. Along with simplifying FIR filters, the more complex filters and signal processing primitives such as IIR and FFT are easily implemented , , , , gain ; Which numbers would you rather work with? 0x , 0xFE000000, 0x , 0xFE43C256, 0x00CE9C00 gain 0x00B0AC5F
9 © 2010 Renesas Electronics America Inc. All rights reserved. Lab Agenda System Block Diagram Analog filter Data Collection Filter Review View and Collect Data Fix “bad” FIR filter Implement Floating Point IIR Implement Fixed Point IIR Summary
10 © 2010 Renesas Electronics America Inc. All rights reserved. Hypothetical Filter Applications
11 © 2010 Renesas Electronics America Inc. All rights reserved. SH7216 allows triggering ADC from MTU2 (timer) DMAC transfers data to buffer ADC Considerations - Benchmark Example Using the HW assist to acquire and transfer data to buffer saves 7% CPU BW Data gets “replaced” right here since We don’t have 30 Function Generators
12 © 2010 Renesas Electronics America Inc. All rights reserved. FIR Filters
13 © 2010 Renesas Electronics America Inc. All rights reserved. Filter Applications – The Boxcar Filter Very common to perform a “running” average Sum n samples, scale the output (usually divide by n) Recalculate each time one new sample comes in Very simple FIR called boxcar All coefficients equal to 1 Example of 8 kHz sampling rate, 8 tap FIR
14 © 2010 Renesas Electronics America Inc. All rights reserved. Filter Types - FIR Typically the gain = 1 Decimation can be on front or back end Lab: back-end decimation X[n] – Input samples nD – Decimation Factor Y”[n] – Decimated Output B[n] – Coefficients (multiplies) Z -1 – Delay elements (storage array)
15 © 2010 Renesas Electronics America Inc. All rights reserved. IIR Filters
16 © 2010 Renesas Electronics America Inc. All rights reserved. IIR Since round-off error in output feeds back IIR requires greater precision 16 bit precision typically sufficient for FIR IIR requires 32 bit precision 1 Floating point simplifies math Not as many IIR design tools
17 © 2010 Renesas Electronics America Inc. All rights reserved. Effects of Quantization Error
18 © 2010 Renesas Electronics America Inc. All rights reserved. Effects of Quantization Error
19 © 2010 Renesas Electronics America Inc. All rights reserved. Why use IIR Design 5 kHz bandpass Sampling rate 44 kHz Center Frequency - 5 kHz Passband - 1 kHz Stopband attenuation 40 dB Passband ripple = 2 dB FIR filter requires 132 taps: IIR filter only requires 17 taps (13 non-zero) Forward coefficients – 1,0,-4,0,6,0,-4,0,1 Feedback coefficients , , , ,
20 © 2010 Renesas Electronics America Inc. All rights reserved. Designing the Filter Programs like ScopeFIR or WinFilter allow simple design of the filter
21 © 2010 Renesas Electronics America Inc. All rights reserved. Frequency Response of 8 Tap 4 kHz Filter -12dB line 20 dB attenuation at 8 kHz compared to 12 for analog filter
22 © 2010 Renesas Electronics America Inc. All rights reserved. Improved 4 kHz Filter By using 14 taps notice the improved attenuation at 6 kHz
23 © 2010 Renesas Electronics America Inc. All rights reserved. Pop Quiz If I chose a sample rate of 20kHz and feed it into a FIR filter with Decimation 4, what “sampling” frequency do I use when I am determining my coefficients? 20k 10k 5k None of the above Depends on where the decimation is. 5k if decimated on front end, 20k if decimated on back end
24 © 2010 Renesas Electronics America Inc. All rights reserved. Start the Lab Keep your dice turned to the section of the lab you are on. (Instructions are provided in the lab handout) Please refer to the Lab Handout and let’s get started!
25 © 2010 Renesas Electronics America Inc. All rights reserved. Checking Progress We are using the die to keep track of where everyone is in the lab. Make sure to update it as you change sections. When done with the lab, your die will have the 6 pointing up as shown here.
26 © 2010 Renesas Electronics America Inc. All rights reserved. Questions?
27 © 2010 Renesas Electronics America Inc. All rights reserved. Lab Questions, Section 1: 1.1 This is a limitation in HEW Waveform plot. If you need to see data in correct scale export and use Excel, etc ScopeDSP is restricted in the file data. 1.3 No, Excel and other programs can just import the data as is excluding colums and rows as necessary.
28 © 2010 Renesas Electronics America Inc. All rights reserved. Lab Questions, Section 2: 2.1 Filter 1 should have been a High pass filter showing more 1K than 60Hz 2.2 Filter 2 should be Low-pass.
29 © 2010 Renesas Electronics America Inc. All rights reserved. Lab Questions, Section 3: 3.1Did you get any warnings or errors when you put in the new coefficients? Yes 3.2If YES, why? coefficients were “larger” than float. 3.3Any need to worry about “scaling”? No 3.4Do the new coefficients improve the filter? Yes 3.5How much improvement, if any did you realize by just changing coefficients? Should be about db
30 © 2010 Renesas Electronics America Inc. All rights reserved. Lab Questions, Section 4: 4.1 Why did we choose for sampling frequency on design? FIR runs at 20kHz we decimate output 4.2 What is the difference in the number of calculations for one pass of FIR versus one pass of IIR? 4 versus “Persistent” Storage difference between IIR and FIR? 4 elements versus 7
31 © 2010 Renesas Electronics America Inc. All rights reserved. Lab Questions, Section 5: 5.1 Does the output look the same as the float IIR? No it will be “ragged” 5.2 If any difference, what can you attribute this to? Quantization error
32 © 2010 Renesas Electronics America Inc. All rights reserved. Lab Questions, Section 6: 6.1 What happens when we try to implement? Cannot implement due to Quantization error 6.2 What is solution if any? More bits of resolution 32 bit fixed or floats 6.3 What are the “float point” values of the coefficients of the first? 6.4 What is the “float point” value of the Gain of the first? 6.5 How are these coefficients for “Readability” in your code? For 6.3 through 6.5 you just need to divide the hex number by the resolution you save them in, in this case 2^24.
33 © 2010 Renesas Electronics America Inc. All rights reserved. Innovation Arc Fault Circuit Interrupter AED
© 2010 Renesas Electronics America Inc. All rights reserved. 34 Thank You!
© 2010 Renesas Electronics America Inc. All rights reserved. 35 Appendix: Additional Information
36 © 2010 Renesas Electronics America Inc. All rights reserved. Resources ScopeFIR, ScopeIIR and ScopeDSP The Scientist and Engineer's Guide to Digital Signal Processing, copyright © by Steven W. Smith. For more information visit the book's website at: C. E. Shannon, "Communication in the presence of noise", Proc. Institute of Radio Engineers, vol. 37, no. 1, pp. 10–21, Jan Reprint as classic paper in: Proc. IEEE, vol. 86, no. 2, (Feb. 1998) C. E. ShannonReprint as classic paper in: Proc. IEEE, vol. 86, no. 2, (Feb. 1998) Rev. 1.00DateMeeting Title
Renesas Electronics America Inc.