Developing a bicycle speed-o-meter A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332.

Slides:



Advertisements
Similar presentations
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Advertisements

Embedded System Timers Details of independent timers build into the Blackfin Assignment 2-- Watchdog Timer can be used to prevent the OS system from locking.
Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V.
Boot Issues Processor comparison TigerSHARC multi-processor system Blackfin single-core.
Daddy! -- Where do instructions come from? Program Sequencer controls program flow and provides the next instruction to be executed Straight line code,
This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during.
The planned but unexpected Program Sequencer controls program flow and provides the next instruction to be executed Interrupt – causing and handling.
6/2/2015 Labs in ENCM415. Laboratory 2 PF control, Copyright M. Smith, ECE, University of Calgary, Canada 1 Temperature Sensor Laboratory 2 Part 2 – Developing.
Thermal arm-wrestling Design of a video game using two programmable flags (PF) interrupts Tutorial on handling 2 Hardware interrupts from an external device.
Building a simple loop using Blackfin assembly code M. Smith, Electrical and Computer Engineering, University of Calgary, Canada.
Specialized Video (8-bit) and Vector (16-bit) Instructions on the Blackfin There is always a “MAKE-UP-YOUR-QUESTION-AND-ANSWER-IT” Question on a Dr. Smith.
Developing a bicycle speed-o-meter Part 2 A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332.
Review of Blackfin Syntax Moves and Adds 1) What we already know and have to remember to apply 2) What we need to learn.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach.
Specialized Video (8-bit) and Vector (16-bit) Instructions on the Blackfin Expand on these ideas for Q9 question and answer on the final.
LCD programming Design and implementation details on the way to a valid SPI-LCD interface driver.
Timers and Timing Signals Tutorial. 6/18/2015 Timer Control Copyright M. Smith, ECE, University of Calgary, Canada 2 / 31 Temperature Sensor -- Lab 3.
Understanding the Blackfin ADSP-BF5XX Assembly Code Format
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Laboratory 1 – ENCM415 Familiarization with the Analog Devices’ VisualDSP++ Integrated Development Environment.
Just enough information to program a Blackfin Familiarization assignment for the Analog Devices’ VisualDSP++ Integrated Development Environment.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
Developing a bicycle speed-o-meter Midterm Review.
Blackfin Timers Independent timers build into the processor Watchdog Timer is a major part of Lab. 2 (Code provided to you to use)
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM511.
Generating “Rectify( )” Test driven development approach to TigerSHARC assembly code production Assembly code examples Part 1 of 3.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
ECE Lecture 21 Typical Assembly Language Program Bugs.
Building a simple loop using Blackfin assembly code If you can handle the while-loop correctly in assembly code on any processor, then most of the other.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
Developing a bicycle speed-o-meter
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Generating the “Rectify” code (C++ and assembly code)
Generating “Rectify( )”
SPI Compatible Devices
Thermal arm-wrestling
DMA example Video image manipulation
The planned and expected
Generating a software loop with memory accesses
Comparing 68k (CISC) with 21k (Superscalar RISC DSP)
* M. R. Smith, University of Calgary, Alberta,
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Thermal arm-wrestling
Using Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Expand on these ideas for Q9 question and answer on the final
Thermal arm-wrestling
Concept of TDD Test Driven Development
Blackfin Timers Independent timers build into the Blackfin
Independent timers build into the processor Basis for Lab. 2
DMA example Video image manipulation
Developing a bicycle speed-o-meter
Blackfin Timers Independent timers build into the processor
Independent timers build into the processor
Developing a bicycle speed-o-meter
Developing a bicycle speed-o-meter
Thermal arm-wrestling
Building a simple loop using Blackfin assembly code
Developing a bicycle speed-o-meter Part 2
A first attempt at learning about optimizing the TigerSHARC code
Blackfin Syntax Moves and Adds
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
ECE511: Digital System & Microprocessor
Presentation transcript:

Developing a bicycle speed-o-meter A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 2 General Project concept Magnetic Sensor Signal High speed clock signal Blackfin Programmable Flag (PF) Input Motorola Parallel Interface Timer (PIT) Input

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 3 Main function concept ulong DetermineSpeed(ulong wheelDiameter, ulong clockFrequency) #define ulong unsigned long int; extern “C” ulong CountClockASM(const int); // Assembly code interface extern “C” ulong CalculateSpeedASM(ulong, ulong, ulong); extern “C” void SetupInterface(void); ulong DetermineSpeed(ulong wheelDiameter, ulong clockFrequency) { // Get to known position on magnetic sensor signal unsigned long discard_count; unsigned long count_high, count_low; SetupInterface( ); discard_count = CountClockASM(while_MagneticSensorHigh); discard_count = CountClockASM(while_MagneticSensorLow); count_high = CountClockASM(while_MagneticSensorHigh); count_low = CountClockASM(while_MagneticSensorLow); return CalculateSpeedASM(count_high + count_low, wheelDiameter, clockFrequency); }

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 4 Required Assembly Language extern “C” ulong CountClockASM(const int); // Assembly code interface extern “C” void SetupInterface(void); extern “C” ulong CalculateSpeedASM(ulong, ulong, ulong); ulong CountClockASM(const int high_low) { ulong clock_count = 0; while (magnetic_sensor = = high_low) { // if signal is unchanged from start // Must count just one clock signal low-to-high transition while (clock_signal = = high) /* wait */; while (clock_signal = = low) /* wait */; // Changes on low-to-high edge clock_count++; } return clock_count; }

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 5 What we need to know How can you pass parameters between “C/C++” and assembly code functions? How can you return a parameter from assembly code functions? What registers are available on the processor? How do you set up the interface between the processor and the real world Many signals are coming into processor, how do you separate (mask off) the signals you want from those you don’t? What are the basic operations for accessing memory? What are the basic ALU operations for this processor?

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 6 Some characteristics of the processor MotorolaBlackfin Data Bus16 bits32 bits Instruction BusThis is the “data” bus64-bits Can fetch “data” on one bus and “instructions” on another bus at the same time Address bus24-bits Accessing “slow” external memory 32 bits Has both “fast” internal memory and “slower” external memory

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 7 Programming model MC68332Blackfin Data RegistersD0, D1 …. D7R0, R1 …. R7 Address RegistersA0, A1 …. A6 Pointer RegistersP0, P1 … P5 Frame Buffer Use A4 or A6FP Stack PointerSP (A7)SP Special DSP I0-I3, B0-B3, M0-M3, L0-L3

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 8 Syntax examples MC68332Blackfin Register to Register Move reg1  reg 2 32 bit operations MOVE.L D2, D1 (4 8 MHz) R1 = R2; (1 500 MHz) Register to Register Move reg1  reg 2 16 bit operations MOVE.W D2, D1R1.L = R2.L; and also R1.H = R2.L; Register to Register Move reg1  reg 2 8 bit operations MOVE.B D2, D1 MOVE.B D2, D1 EXT.B D1; (8 8 MHz) R1 = R2.B (X); (1 500 MHz)

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 9 Syntax examples MC68332Blackfin Register to Register ADD reg1  reg 2 + reg3 32 bit operations MOVE.L D2, D1 ADD.L D3, D1 (10 8 MHz) R1 = R2 + R3; (1 500 MHz) Register to Register Move reg1  reg 2 + reg3 16 bit operations MOVE.W D2, D1 ADD.W D3, D1 (8 8 MHz) R1.L = R2.L + R3.L (NS); (1 500 MHz) Also R1 = R2 +|- R3; Means R1.L = R2.L – R3.L; and R1.H = R2.H + R3.H; Register to Register Move reg1  reg 2 + reg3 8 bit operations MOVE.B D2, D1 ADD.B D3, D1 R1.L = R2.B (X); R0.L = R3.B (X); R1.L = R1.L + R0.L (NS); ( > MHz)

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 10 In class exercise Do what?

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada bit Memory Move operations MotorolaBlackfin Value at memory location 1 placed at memory location 2 MOVE.L #MEM1, A0 MOVE.L #MEM2, A1 MOVE.L (A0), (A1) 36 8 MHz P0.H = hi(MEM1); P0.L = lo(MEM1); P1.H = hi(MEM2); P1.L = lo(MEM2); R0 = [P0]; [P1] = R0; > 6 cycles Multiple moves MOVE.L #MEM1, A0 MOVE.L #MEM2, A1 MOVE.L (A0)+, (A1)+ P0.H = hi(MEM1); P0.L = lo(MEM1); P1.H = hi(MEM2); P1.L = lo(MEM2); R0 = [P0++]; [P1++] = R0; R0 = [P0++]; [P1++] = R0; R0 = [P0++]; [P1++] = R0;

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada bit Memory Move operations MotorolaBlackfin Value at memory location 1 placed at memory location 2 MOVE.L #MEM1, A0 MOVE.L #MEM2, A1 MOVE.W (A0), (A1) 36 8 MHz P0.H = hi(MEM1); P0.L = lo(MEM1); P1.H = hi(MEM2); P1.L = lo(MEM2); R0 =W [P0]; W[P1] = R0; > 6 cycles Multiple moves MOVE.L #MEM1, A0 MOVE.L #MEM2, A1 MOVE.W(A0)+, (A1)+ P0.H = hi(MEM1); P0.L = lo(MEM1); P1.H = hi(MEM2); P1.L = lo(MEM2); R0 = W[P0++] (X); W [P1++] = R0; R0 = W[P0++] (X); W[P1++] = R0; R0 =W [P0++] (X); W [P1++] = R0;

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 13 Memory Move operations MotorolaBlackfin Multiple moves of registers MOVEM.L D0-D3/A0-A5, -(SP) [- - SP] = (R7:5, P5:3); Combination of memory moves and ALU operations Can also do parallel read and write operations together with math operations Syntax looks like this R1 = R2 | | R3 = [I0++] | | [I1++] = R4; Not all operations can be made parallel

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 14 In class exercise Do what

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 15 If – then – else constructs Signed tests MotorolaBlackfin Set the condition code register CMP.L D0, D1CC = D1 == D0; CC = D1 < D0; CC = D1 <= D0; Conditional jumpBEQ NEXT_INSTR (D1 == D0) BLT NEXT_INSTR (D1 < D0) BLE NEXT_INSTR (D1 <= D0) IF CC JUMP NEXT_INSTR BNE NEXT_INSTR (D1 <> D0) BGE NEXT_INSTR (D1 >= D0) BGT NEXT_INSTR (D1 > D0) IF !CC JUMP NEXT_INSTR

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 16 If – then – else constructs Un-signed tests MotorolaBlackfin Set the condition code register CMP.L D0, D1CC = D1 == D0 (UI); CC = D1 < D0 (UI); CC = D1 <= D0 (UI); Conditional jumpBEQ NEXT_INSTR (D1 == D0) BLO NEXT_INSTR (D1 < D0) BLS NEXT_INSTR (D1 <= D0) IF CC JUMP NEXT_INSTR BNE NEXT_INSTR (D1 <> D0) BHS NEXT_INSTR (D1 >= D0) BHI NEXT_INSTR (D1 > D0) IF !CC JUMP NEXT_INSTR

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 17 Example if-then-else code C++ exampleMotorolaBlackfin IF (A > B) C = D; ELSE C = E; Set A, B, C, D, E to registers D0, D1,.. D4 CMP.L D1, D0 BLE ELSE MOVE.L D3, D2 JMP END_IF ELSE: MOVE.L D4, D2 END_IF: Set A, B, C, D, E to registers R0, R1,.. R4 CC = R1 < R0; IF !CC JUMP ELSE; R2 = R3; JUMP END_IF; ELSE: R2 = R4; END_IF: CC = R1 < R0; IF CC R2 = R3; IF !CC R2 = R4;

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 18 Example loop code -- software loop C++ exampleMotorolaBlackfin sum = 0; for (loop = 0; loop < 6; loop++) sum = sum + loop; Set D0 = sum, D1 = loop MOVE.L #0, D0 MOVE.L #0, D1 LOOP: CMP.L #6, D1 BGE PAST_LOOP ADD.L D1, D0 ADD.L #1, D1 BRA LOOP PAST_LOOP: Set R0 = sum, R1 = loop R0 = 0; R1 = 0; R2 = 6; LOOP: CC = R2 <= R1; IF !CC JUMP PAST_LOOP; R0 = R0 + R1; R1 += 1; JUMP LOOP PAST_LOOP:

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 19 Example loop code -- Harware loop C++ exampleMotorolaBlackfin sum = 0; for (loop = 0; loop < 6; loop++) sum = sum + loop; Set D0 = sum, D1 = loop MOVE.L #0, D0 MOVE.L #0, D1 LOOP: CMP.L #6, D1 BGE PAST_LOOP ADD.L D1, D0 ADD.L #1, D1 BRA LOOP PAST_LOOP: Set R0 = sum, R1 = loop R0 = 0; R1 = 0; P1 = 6; LSETUP(LSTART, LEND) LC1 = P1; LSTART: R0 = R0 + R1; LEND: R1 += 1; PAST_LOOP: Has a capability of 2 hardware (high- speed, zero overhead) loop

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 20 Hardware test – wait while magnetic signal is “high” C++MotorolaBlackfin Magnetic SignalBit 1 of PADR register of PI/T interface Bit 10 of FIO_FLAG_D register of PF interface while (mag_signal == HIGH) /* wait */ ; MASK EQU 0x1 MOVE.L #PITBASE, A0 WHILE: MOVE.B PADR(A0), D0 AND.B #MASK, D0 CMP.B #MASK, D0 BEQ WHILE #define MASK 0x400 P0.H = hi(FIO_FLAG_D); P0.L = lo(FIO_FLAG_D); R1 = MASK; WHILE: R0 = W[P0] (Z); R0 = R0 & R1; CC = R0 == R1; IF CC JUMP WHILE (BP);

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 21 Subroutine / Function calls C++MotorolaBlackfin extern “C” int FooASM(int, int, int) C = FooASM(1,2,3).IMPORT _FooASM FP EQU A6 LINK FP, -16 MOVE.L D4, 12(SP) MOVE.L #1, 0(SP) MOVE.L #2, 4(SP) MOVE.L #3, 8(SP) JSR _FooASM MOVE.L D0, D4.. Other code MOVE.L 12(SP), D4 UNLINK RTS.extern _FooASM LINK 20; [SP + 16] = R4; R0 = 1; R1 = 2; R2 = 3; CALL _FooASM; R4 = R0;.. Other code R4 = [SP + 16]; UNLINK; RTS;

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 22 Code conventions for subroutines / functions Motorola -- SDSBlackfin -- VisualDSP Volatile registersD0, D1 A0, A1 R0, R1, R2, R3 P0, P1, P2 Non-volatile registersD2, D2, D4, D5, D6, D7 A2, A3, A4, A5, A6, A7 R4, R5, R6, R7 P3, P4, P5, FP, SP Subroutine return value is passed in D0R0 Subroutine OUTPARSOUTPAR1  0(SP) OUTPAR2  4(SP) OUTPAR3  8(SP) OUTPAR4  12(SP) OUTPAR1  R0 OUTPAR2  R1 OUTPAR3  R2 OUTPAR4  12(SP)

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 23 In class exercise Do what?

6/13/2015 Motorola Blackfin Comparison Part 1, Copyright M. Smith, ECE, University of Calgary, Canada 24 Information taken from Analog Devices On-line Manuals with permission Information furnished by Analog Devices is believed to be accurate and reliable. However, Analog Devices assumes no responsibility for its use or for any infringement of any patent other rights of any third party which may result from its use. No license is granted by implication or otherwise under any patent or patent right of Analog Devices. Copyright  Analog Devices, Inc. All rights reserved.