over-view of lab. 1 see the lab. 1 web-site and later lecture notes for more details

24
Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

Upload: steven-fletcher

Post on 12-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

Over-view of Lab. 1

See the Lab. 1 web-site and later lecture notes for more details

Page 2: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

All embedded projects (every one built in the world) require the followingBuild a “project” directory using a “development

environment.Add code to -- CODE IS RE-USED IN LATER LABS

Initialize the system Read general purpose input signals (I part of GPIO) Write general purpose output signals (O part of GPIO) Initialize and use peripherals

Timers, serial interfaces to LCD screens, thermal sensors, light sensors, accelerometers, DSP programs for analysis

Build system in a controlled and testable manner Incremental build, testing framework Operating system (Super loop, co-operative scheduler, event

driven scheduler)2 /23

Page 3: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

E.g. Radio controlled voice activatedrobotic car “term” projectSet-up the processor to control the board A/D and

D/A; allows capture and play-back sound.Set-up the processor so that we can read general

purpose input lines (GPIO -- switches) so we send various different commands to car.

Use the digital signal processing (DSP) part of Blackfin processor to run canned (meaning written by somebody else) frequency analysis program to recognize voice commands

Use the analysis of the sounds to output control values to a radio transmitter and control the car.

3 /23

Page 4: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

4 /23

Main Code – pseudo code for the “voice controlled car” main( ) { // red – means canned code – green means done in Lab. 1

Launch the Analog Devices audio “echo” program – a background interrupt-driven task that is given to you – you will modify this code

InitFlashASM( ); // Activate the system Flash memory without // stopping audio program which uses the Flash interface too // This enables you to write to the LED’s on the Blackfin board

InitializePFInterfaceASM( ); // Activate the Push-button controller // This enables you to read switches SW1, SW2, SW3, SW4

Launch “VDK multi-threads” (separate processes) to control various processes // The VDK O/S is provided as part of the VDSP IDE

Thread 1 – Captures and then stores batches of sound for analysisThread 2 – Analyze previous stored sound for possible “commands”Thread 3 – Use previous commands to send commands to control the carThread 4 – Check evaluation buttons for “options” (autopilot etc)Thread 5 etc

Page 5: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

5 /23

Another possible example project using the same code ideasWe want to build a audio controller

Reuse CANNED examples provided by Analog DevicesAudio in captured using audio A/D (CODEC)Audio out generated using audio D/A (CODEC)

Manipulate the sound qualityModify functions that use Lab. 1 hardware interfaces

Push buttons to control audio controller operations – e.g. graphics equalizer

LED lights to display operation results and sound volume level (dancing lights)

Page 6: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

6 /23

Main Code – pseudo code for the “audio controller”main( ) {

Launch the Analog Devices audio “echo” program – a background interrupt-driven task that is given to you – you will modify this code

InitFlashASM( ); // Activate the system Flash memory without stopping // the audio program which uses the Flash interface too

InitializePFInterfaceASM( ); // Activate the Push-button controller

Wait for button1 to be pressed and released (ReadButtonASM() ), then play the sound at half-volume.

Wait for button2 to be pressed and released, play the sound at normal volumeWhen button3 is pressed -- Generate the extremely fascinating (but

completely useless) dancing lights which change with the audio stream volume level

Wait for button4 to be pressed and released, quit the program (turn off the sound and stop the processor)

}

Page 7: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

7 /23

If we wanted to get fancy we could do the following to the audio Talkthrough program

Gargling operation Need to add a simple counter that increments by

1 every 1 / 44000 s (increments each time that an audio sample is obtained)

Use the counter to control when to turn the sound off and on every ½ s

Gargling sound is produced rather than just “turning the sound off”

For more details – see Lab. 1 from 2006.

Page 8: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

8 /23

Lab. 1 – Key project interfacingMicrocontroller I/O demonstration Your group must come into the laboratory class prepared to be able to

demonstrate all of the following by the end of laboratory period You will make use of some of the code developed during the assignments.

(Note assignments may be due AFTER the laboratory) Initialize the push-button controller interface

Read, and use, a value provided by the push-button controller. Initialize the Flash LED display interface (so that it works)

Write a value to the LED display Read, and use, a value stored in the LED display, so you can test that you

are getting the correct answer Demonstrate tests to show that these operations work as required

OPTIONAL “ENCM511 Project club” Each laboratory will provide you with enough interface information to get a component

of the voice-activated radio control car to work. Extra hours of work will needed to write and test the necessary C++ code to make the

interfaces operate correctly – but that can be split amongst those interested.Develop a voice activated “Windows Mobile cell-phone application”

Page 9: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

9 /17

Lab. Task – Does my ADSP-BF533 board work? Download audio-talk-through program

If you have not already done so, download and expand ENCM511Directory2010.zip file (used in assignment 1) so that you have the correct directory. structure and test driven development environment needed for Laboratory 1.

Download and expand the files in 10CPP_Talkthrough.zip into your AudioDemo directory.

Build an AudioDemo Blackfin project in your AudioDemo directory and add the (provided) files into the project -- compile and link.

Download the executable (.dxe) file onto the BF533 processor.

Hook up your CD or IPOD output to the CJ2 stereo input. Hook up your ear-phones to the CJ3 stereo output. Run the AudioDemo.dxe executable and check that the talk through

program is working.

This task demonstrated your ability to build VDSP Blackfin projects and run the code (Marks for Familiarization Lab). The AudioDemo code (running in a multithread environment) forms the basis of the (optional) voice-activated radio-controlled car project.

Page 10: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

Tasks of Laboratory 1

Basic Task – develop the LED interface Initialize the Flash memory using the Blackfin

External Bus Interface Unit (EBIU) (ASM) Initialize the memory controller of the Blackfin Evaluation Board LED’s

(ASM) – can control devices and write large code The Blackfin external bus interface unit is used to perform many

“microcontroller” operations Initialize SDRAM, audio chips etc,

Task (mainly in C++) that use the LED interface E.g. Develop a simple counter (in C++) and display value E.g. Write a C++ routine to write morse code values into an array E.g. Write a routine to transfer the morse code values to the LED’s

(first in C++, then ASM)homepage.ntlworld.com/dmitrismirnov/morse-tab1.JPG

10 /23

Page 11: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

11 /23

Task – Initialize the Programmable flag interface – 16 GPIO lines on the Blackfin

Warning – could burn out the Blackfin processor if coding is done incorrectly

You need to set (store a known value to) a number of internal registers in the Blackfin processor core.Other processors need equivalent GPIO control methods

Most important registersFIO_DIR – Data DIRection – set to value ?? for input ****FIO_INEN – INterface Enable – set to value ?? for enabling the

input (otherwise they will not work – power saving)FIO_FLAG_D – Programmable FLAG Data register

Page 12: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

12 /23

Why do you need to know how to do read (load) and write (store) on internal registers?

Flag Direction register (FIO_DIR) Used to determine if the PF bit is to be used for input or output

-- WARNING SMOKE POSSIBLE ISSUE USE equivalent of AND instruction from ENCM369 to clear bits PF11 to

PF8 to 0 for input, but must leave all other bits unchanged in value. Read peripheral register value, use AND instruction to zero the required bits, write back

value

Page 13: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

13 /23

Registers used to control PF pins

Flag Input Enable Register Only activate the pins you want to use (saves power in

telecommunications situation) USE OR instruction from ENCM369 to enable (activate) pins PF11

to PF8 for input, leave all other bits in register unchanged Read peripheral register value, use OR instruction to SET the required bits, write back value

Page 14: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

14 /23

Registers used to control PF pins

Flag Data register (FIO_FLAG_D) Used to read the PF bits (1 or 0) Need to read pins PF11 to PF8, ignore all other pins values. This requires AND

and SHIFT instructions from ENCM369. Read register value, use AND instruction to clear unwanted bits, then use masked value in code

Page 15: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

WarningThe class notes remind you of the following

important facts USE equivalent of AND instruction from ENCM369 to clear bits PF11 to PF8 to 0 for input, but must leave

all other bits unchanged in value. Read peripheral register value, use AND instruction to zero ONLY the required bits, write back value

USE OR instruction from ENCM369 to enable (activate) pins PF11 to PF8 for input, leave all other bits in register unchanged

Read peripheral register value, use OR instruction to set ONLY required bits to 1, write back value

These techniques were demonstrated in the tutorial this morning (Friday 24)

The lab pages WILL NOT remind you of those following important facts

This will give you the opportunity to make ‘real-life’ mistakes in the laboratory and work out how to recognize that problems are occurring and fix problems.

15 /18

Page 16: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

16 /23

Task – Setting up the programmable flag interface

Follow the instructions carefullyFIO_DIR – direction register – write 0’s to bits 8, 9, 10, 11 –

leave other bits unchanged (READ / then AND / WRITE operations) -- This sets the pins as INPUT pins

FIO_INEN – input enable register – write 1’s to bits 8, 9, 10, 11 – leave other bits unchanged (READ / then OR / WRITE operations) – This activates (turns on) the pins as INPUT pins

Other GPIO registers write 0’s to bits 8, 9, 10, 11 – leave other bits unchanged (READ / then AND / WRITE operations)

There is a test program that will enable you to check your code – provide a screen dump of test result.

Page 17: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

17 /23

Task – Read the switches on the front panel in “real life”Transfer the information to the LEDs so you can demonstrate

correct operationsBuild Initialize_ProgrammableFlagsASM ( )

MUST HAVE 50 pin cable connected between logic board and Blackfin for the switch values to be read correctly – otherwise switch input always reads “1”. Watch the demonstrations

Logic board power supply must be turned on (or your code will always read 1 from the switches)

What we could do – “Simple optical transmitter project” Place a “light sensitive detector” in front of the LEDs on a “second” Blackfin

station where that station is sending morse messages. Use the output of the detector as the input to the “First Blackfin” instead of

the switch, and capture the light code signals Print out the “morse” code transmissions on the screen of the “first” station

– very basic optical transmission

Page 18: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

18 /23

#include <blackfin.h>

.global _ReadGPIOFlags;

_ReadGPIOFlags:

// Make an address register “point” to

// the GPIO Flag register to read switches

P1.L = lo (FIO_FLAG_D);

P1.H = hi (FIO_FLAG_D);

// Read the “16” bit flag register value and return // the value for the C++ code to use

R0 = W[P1] (Z); // convert 16 to 32 bits_ReadGPIOFlags.END: RTS;

Must use W [ ] 16-bit read since the manual shows that FIO_FLAG_D register is 16-bits

ZERO EXTENSIONMust use W[P1] (Z) zero-extend as this adds 16 zeros to the 16 bits from FIO_FLAG_D register to make 32-bits to place into R0

0xFF00 becomes 0x0000FF00

extern “C” int ReadGPIOFlags( )

Page 19: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

19 /17

FLAG REGISTER HOLD BIT-PATTERNS NOT NUMBERS

The audio chip brings in 24 bit values representing the digital value (positive or negative) of the audio volume Negative values 0x800000 (-2^23) to 0xFFFFFF (-1)

Positive values 0x000000 (0) to 0x7FFFFF (2^23 -1).

However, the values are read into the Blackfin 32 bit data register as values the audio volume (ZERO EXTENSION)

Positive values 0x00800000 (PLUS 2^23) to 0x00FFFFFF (PLUS 2^24 - 1)

Positive values 0x0000000000 (0) to 0x00007FFFFF (2^23 -1)

Audio signal will sound very distorted unless sign extension applied

Negative values 0xFF800000 (- 2^23) to 0xFFFFFFFF (- 1)

Positive values 0x0000000000 (0) to 0x00007FFFFF (2^23 -1)

FLAG DATA REGISTER ZERO EXTENSIONMust use W [ ] 16-bit read since the manual shows that FIO_FLAG_D register is 16-bits

Must use W[P1] (Z) zero-extend as this adds 16 zeros to the 16 bits from FIO_FLAG_D register to make 32-bits to place into R0

0xFF00 becomes 0x0000FF00

Sign extension of input often needed

Page 20: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

Using that assembly code to just wrote from C++ extern “C” int ReadGPIOFlags( );

int ReadPushButtonSwitches(void) {

InitializeGPIORegisters( ); // Lab. 1

int GPIOFlagValues = ReadGPIOFlags( ); // Must happen AFTER Init( ) or // garbage results are obtained

int maskToRemoveUnwantedBits = 0x0F00;

// Review of ENCM369 – AND operation & and NOT &&

int wantedGPIOFlagValues = GPIOFlagValues & maskToRemoveUnwantedBits;

return (wantedGPIOFlagValues >> 8); // bit shift operation

}

Returns 1 if switch 1 pressed, returns 2 if switch 2 pressed,

Returns 4 if switch 3 pressed, returns 8 if switch 4 pressed,

Returns 5 if switch 1 and switch 3 are pressed at the same time

20 /23

SW4 SW2 SW3 SW1

Page 21: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

Controlling a radio controlled carusing the pushbuttons

A L F RSwitch 2 pressed means go forward for 1/ 2 sSwitch 1 means turn wheels rightSwitch 3 means turn wheels leftSwitch 4 means accept command

(Later replace switch control with music / voice control)

Thus pressing switches 2, 2, 1 with 2, 2, 2, 3 with 2, 2, 2, 0, 0, 0, 0

Would cause the car to go down an “S” shape path21 /23

Page 22: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

Store the commands to control a car into an array for later play-back #define STOP 0

int storeCommands[20];

int numberStopCommands = 0;

int count = 0;

while (numberStopCommands < 4) {

command = GetValidCommand( );

if (command == STOP) {

numberStopCommands ++;

}

else {

numberStopCommands = 0;

}

storeCommands[count++] = command;// System crashes is more than 20 commands are entered – WHY?? – good mid term question// Is the way that viruses cause overflow of input buffer problem

}

22 /23

Page 23: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

Get a valid command to control a car

#define SWITCH4 0x8

#define ACCEPTCOMMAND SWITCH4

int GetValidCommand( ) {

int command = ReadPushButtonSwitches( );

while ( (command & ACCEPTCOMMAND) != ACCEPTCOMMAND} {

command = ReadPushButtonSwitches( );

}

// Get here when somebody pushes switch 4

// Explain why it is a logical error if we just exit this code here

// NOT fixing this error will cause “mucho-grief” in the lab – work out the problem with your lab partner

return command;

}

23 /23

Page 24: Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details

24 /24

Task -- Tests

There needs to be software tests (E-TDD) to allow you to demonstrate that your code works correctly

Note there are test executables (.dxe) available to test out your equipmentThis code can be used to test the switches and the

LED interface on your board. SwitchToLED.dxe This is the final version of my code for the “fancy”

audio controller  DrSmithAudioController.dxe