Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.

Slides:



Advertisements
Similar presentations
Getting the O in I/O to work on a typical microcontroller Activating a FLASH memory “output line” Part 1 Main part of Laboratory 1 Also needed for “voice.
Advertisements

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.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Over-view of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
A look at interrupts What are interrupts and why are they needed.
Microprocessor and Microcontroller
I/O Unit.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 3 – New instruction recap Tutorial.
EET 2261 Unit 9 Interrupts  Read Almy, Chapters 17 – 19.  Homework #9 and Lab #9 due next week.  Quiz next week.
Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Lab. 1 – Earlier Tasks. Needed by both application and demonstration lab. streams For more details – see the Lab. 1 web-site There will be a 20 min prelab-quiz.
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.
Over-view of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
Lab. 1 – Task 1 to 4 details For more details – see the Lab. 1 web-site There will be a 20 min prelab-quiz (based on Assignment 1 and 2) at the start of.
Lab. 2 – More details – Tasks 4 to 6 1. What concepts are you expected to understand after the Lab. 2 is finished? 2. How do you demonstrate that you have.
A look at interrupts What are interrupts and why are they needed in an embedded system? Equally as important – how are these ideas handled on the Blackfin.
Over-view of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
A look at interrupts What are interrupts and why are they needed.
Getting the O in I/O to work on a typical microcontroller Ideas of how to send output signals to the radio controlled car. The theory behind the LED controller.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Getting the O in I/O to work on a typical microcontroller Activating a FLASH memory “output line” Part 1 Main part of Laboratory 1 Also needed for “voice.
Just enough information to program a Blackfin Familiarization assignment for the Analog Devices’ VisualDSP++ Integrated Development Environment.
Blackfin BF533 EZ-KIT Control The O in I/O
Later tasks of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
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.
HD44780 LCD programming From the Hardware Side
Developing a bicycle speed-o-meter Midterm Review.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
COMP201 Computer Systems Exceptions and Interrupts.
Input Laboratory: GPIO Pin control needed to have the Blackfin accept your commands Re-uses information from ENEL353 and ENCM369 courses and text books.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 9/19/2015 Review of 50% OF ENCM369 in 50 minutes1.
3-1 Digital I/O A group of I/O pins is called a PORT  A port is where data enters/leaves the system. Digital I/O pins are usually grouped into 8,16 or.
Over-view of Lab. 1 See the Lab. 1 web-site and later lecture notes for more details.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);
Lab. 1 – Required Tasks. For more details – see the Lab. 1 web-site.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Over-view of Lab. 1 See the Lab. 1 web-site and the lecture notes for more details.
Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1.
Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 3/3/2016 Review of 50% OF ENCM369 in 50 minutes1.
Over-view of Lab. 1 See the Lab. 1 web-site and latter lecture notes for more details.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
The 8085 Microprocessor Architecture
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.
See the Lab. 1 web-site and later lecture notes for more details
Chapter 10 And, Finally... The Stack
Developing a bicycle speed-o-meter
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Assembly Language Review
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Assembly Language Review
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
See the Lab. 1 web-site and later lecture notes for more details
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.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Input Laboratory: GPIO Pin control needed to have the Blackfin accept your commands Re-uses information from ENEL353 and ENCM369 courses and text books.
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Developing a bicycle speed-o-meter
Blackfin BF533 EZ-KIT Control The O in I/O
Developing a bicycle speed-o-meter
Presentation transcript:

Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual

What is a switch? 2 /25 SPRING TO CAUSE SWITCH TO OPEN AFTER PUSH TO CLOSE PRESS DOWN TO CLOSE SWITCH OUTPUT SWITCH INPUT

Normally one side of switch is grounded, the other side connected to microcontroller GPIO input 3 /25 BLACKFIN GPIO LINES PF8, PF9, PF10, PF11 GROUND (0V) INPUT IS 0V INPUT IS ????? FLOATING

One side of the switch must be pulled “softly” to 3 V / 5V (pull up resistor) 4 /25 BLACKFIN GPIO LINES PF8, PF9, PF10, PF11 GROUND (0V) INPUT IS 0V 10k “Pull-up” resistor 3v INPUT IS 5V

Blackfin has a GPIO data register 16 GPIO lines come into the register Registers are based on flip-flops to store whether the input is 3V (high) or zero (low) 16 flip flops put together make the FIO_FLAG_D register The GPIO data register is memory mapped so no special instructions needed, you “treat it as if it was the same as any other memory” When you “read” from the GPIO register, you cause a “load” of the input values into the flip- flop and out onto the microcontroller’s data bus 5 /25

6 /25 Registers used to control PF pins Flag Data register (FIO_FLAG_D)  Used to read the PF bits as an input -- (1 or 0)  Need to read pins PF11 to PF8 ONLY, ignore all other pins values Read the value, AND off unwanted bits, then use it

What we know about the way “front panel” switches connected to BF533 SW1 is connected to PF8 SW2 is connected to PF9 SW3 is connected to PF10 SW4 is connected to PF11 The other pins in the GPIO interface are used for “other” purposes on the Blackfin board and MUST not have their values changed e.g. Video device input port 7 /25

What we want to do Read the GPIO data register Return ONLY the values in pins 8 to 11 which means removing (masking out) the other values  Value read from GPIO data register = 0x4723 We only want to get the bits 0x0700 (SW1, SW2, SW3)  Value read from GPIO data register = 0x4023 We only want to get the bits 0x0000 (no switches)  Value read from GPIO data register = 0x4823 We only want to get the bits 0x0800 (SW4) 8 /25

What we have to code  MASK bit set to 1 for bits we keep, 0 for bits removed MASK = 0x0F00 (Bits 8, 9, 10, 11 are 1, other bits are zero)  Value read from data register = 0x4723 (PF8, 9, 10) We only want to get the bits 0x MASK Result = value & MASK (and operation)  Value read from data register = 0x4023 (none) We only want to get the bits 0x0000 Result = value & MASK (and operation)  Value read from data register = 0x4823 (PF11) We only want to get the bits 0x0500 Result = value & MASK (and operation) 9 /25

So the code required is 10 /25 #include.section program;.global _ReadGPIOFlagsASM; _ReadGPIOFlagsASM: P0.L = lo(FIO_FLAG_D); P0.H = …… R0 = W[P0] (Z); // Convert 16 bits to 32 bits via zero extension // These are “bit settings” not a number #define AND_MASK 0x0F00; R1 = AND_MASK; R0 = R0 & R1; _ReadGPIOFlagsASM.END: RTS;

DOES NOT WORK We have not “initialized” the GPIO device interface “Initialize device” means “prepare the device to make work”, in this case I / O 11 /25 #include.section program;.global _ReadGPIOFlagsASM; _ReadGPIOFlagsASM: P0.L = lo(FIO_FLAG_D); P0.H = …… ………; R0 = R0 & R1; _ReadGPIOFlagsASM.END: RTS;

Initialize the GPIO interface requires change to many control registers Turn the interrupts OFF for PF8 to PF11. Do this WITHOUT changing the interrupt behaviour for the other pins Set the POLARITY register so that a 1 coming into pins PF8 to PF11 is read as a HIGH (1). Do this without changing the POLARITY behaviour of the other GPIO pins. Etc. etc. 12 /25

Initialize the GPIO interface Set the DIRECTION register so that PF8 to PF11 pins are INPUT without changing the behaviour of the other GPIO pins.  IF DONE INCORRECTLY CAN BURN OUT THE CHIP. You don’t want a device sending a 1 to the GPIO interface, while the interface is trying to output a 0. AFTER all other initialization steps are complete  Set the ENABLE register so that pins PF8 to PF11 work without changing the behaviour of the other GPIO pins. Power saving feature 13 /25

So the code required is 14 /25 #include.section program;.global _InitGPIOFlagsASM; _InitGPIOFlagsASM: CALL TurnInterruptsOff_PF8to11; CALL SetPolarity_PF8to11; CALL OtherStuff_PF8to11; CALL SetDirection_PF8to1; CALL Enable__PF8to11; _InitGPIOFlagsASM.END: RTS;

Incorrect code – contains a hidden defect which stops the proper program operation 15 /25 #include.section program;.global _InitGPIOFlagsASM; _InitGPIOFlagsASM: CALL TurnInterruptsOff_PF8to11; // CALL means set RETS register // to point to instruction after CALL // RETS register = address of instruction labelled “next:” next:CALL SetPolarity_PF8to11; next2: CALL OtherStuff_PF8to11; Next3:CALL SetDirection_PF8to1; Next4:CALL Enable__PF8to11; _InitGPIOFlagsASM.END: RTS; // RTS means JUMP RETS // or “Change the PC to the value stored in RETS register // What line of code will be executed? // meaning “where does the code jump to?

Correct code 16 /25 #include.section program;.global _InitGPIOFlagsASM; _InitGPIOFlagsASM: LINK 16;// Save (write) RETS to the stack CALL TurnInterruptsOff_PF8to11; // CALL means set RETS register // to point to instruction after CALL // RETS = next: in this case next:CALL SetPolarity_PF8to11; next2: CALL OtherStuff_PF8to11; Next3:CALL SetDirection_PF8to1; Next4:CALL Enable__PF8to11; UNLINK;// Recover (get back) RETS from the stack _InitGPIOFlagsASM.END: RTS; // This means JUMP RETS // PC set to “saved” RETS so code “returns” to the function that called it

Other GPIO register flip flops FIO_MASKA_D and FIO_MASKB_D If bit X = 1, tell processor to cause an interrupt (change program operation) when FIO_FLAG_D bit X is active (changes to a 1 value) 17 /25

CALL TurnInterruptsOff_PF8to11ASM; 18 /25 #include.section program;.global _TurnInterruptsOff_PF8to11ASM; _ TurnInterruptsOff_PF8to11ASM: P0.L = lo(FIO_MASK_A); P0.H = …… R1 = 0; W[P0] = R0; ssync; // Tell processor to do the write operation NOW // DO same thing for FIO_MASK_B TurnInterruptsOff_PF8to11ASM.END: RTS

P0.L = lo(FIO_MASK_A); P0.H = …… R1 = 0; W[P0] = R0; This puts a 0 in every bit and turns ALL interrupts off – not just bits 8 to /25

CALL TurnInterruptsOff_PF8to11; 20 /25 #include.section program;.global _TurnInterruptsOff_PF8to11; _ TurnInterruptsOff_PF8to11: P0.L = lo(FIO_MASK_A); P0.H = …… R0 = W[P0] (Z); // Read all the bits #define MASK_NOCHANGE_VALUES 0xF0FF R1 = MASK_NOCHANGE_VALUES R0 = R1 & R1;// Bits 8 to 11 zero W[P0] = R0;// But other bits still the same // DO same thing for FIO_MASK_B TurnInterruptsOff_PF8to11: RTS

Lets call a “C++” function instead of writing the code in assembly code 21 /25 #include.section program;.global _InitGPIOFlagsASM; _InitGPIOFlagsASM: LINK 16; CALL TurnInterruptsOff_PF8to11CPP__Fv; // We must use “name mangling” to call C++ code next:CALL SetPolarity_PF8to11; next2: CALL OtherStuff_PF8to11; Next3:CALL SetDirection_PF8to1; Next4:CALL Enable__PF8to11; UNLINK; _InitGPIOFlagsASM.END: RTS; NEW SLIDE

Lets write this code in C instead TurnInterruptsOff_PF8to11CPP__Fv; 22 /25 Place code in “InitGPIO.cpp #include void TurnInterruptsOff_PF8to11CPP(void) { *pFIO_MASK_A = 0; // WRONG – need to use AND operation Ssync( ); // DO same thing for FIO_MASK_B } In assembly code the C++ function TurnInterruptsOff_PF8to11CPP( ) becomes named _TurnInterruptsOff_PF8to11CPP__Fv In assembly code the C function TurnInterruptsOff_PF8to11C ( ) becomes named _TurnInterruptsOff_PF8to11C This convention allows the overloading of C++ functions (but not C) NEW SLIDE

Another GPIO register we need to set correctly 23 /25

Another flip-flop group controls whether the flip-flop outputs follow the flip-flop inputs or are “high impedance” – off – no useful value 24 /25

CALL EnablePins_PF8to11; 25 /25 #include.section program;.global _EnablePins_PF8to11; _ EnablePins_PF8to11: P0.L = lo(FIO_INEN); P0.H = …… #define MASK_CHANGE_VALUES 0x0F00; R1 = MASK_CHANGE_VALUES W[P0] = R1; EnablePins_PF8to11.END: RTS WRONG: True this enables bits 8 to 11, but it also DISABLES all the other bits Need to use “OR” instruction after reading the enable register

A key issue with GPIO is whether a pin is to act as an input device (bringing things in from the outside world into the Blackfin) or as an output device (sending things from the Blackfin to the outside world) 26 /25

27 /25 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  Need to set pins PF11 to PF8 for input, leave all other pins unchanged

28 /25 Write the Blackfin assembly language instruction(s) to load the address of the internal programmable flag FIO_DIR register into pointer register P1 – then SET the Blackfin PF lines to act as inputs #include P1.L = lo (FIO_DIR); P1.H = …. // Check the requirements – need to have all input // Manual says “setting a line for input means setting bit values to 0” R0 = 0; W[P1] = R0; // This changes “All pins” ssync; // Force Blackfin to do the write (store) NOW not later Making sure that the FIO_DIR is correct for LAB. 1 – NOTE may need to change for later labaoratories Design Error “Changes all pins

Notice that previous slide WARNS you about a design error in the code We can’t do things this way as it changes all the bits in the 16 flip-flops and we only want to change 4 values in the flip-flops The same design error is introduced into Lab. 1 Task 3 However, the same design error is found during the TDD tests – provided to look at the test code to see what was being tested 29 /25

These tests DONOT find the design error 30 /25

These tests DO find the design error and in fact explain to you why it is likely that your tests have failed. But you have to read the message about the Test and not ignore it 31 /25

Extra ideas you can use Echoing Values from the switches to the LED 32 /25

33 /25 Echoing the switches to the LED Code in main( ) – written in C++ int main( ) { InitializeGPIOInterface( ); // Check Lab. 1 for “exact name needed” InitializeFlashLEDInterface( ); // Check Lab. 1 for “exact name needed” #define SWITCHBITS 0x0F00 // Look in MIPs notes about // using a mask and the // AND bit-wise operation // to select “desired bits” while (1) { // Forever loop int GPIO_value = ReadBlackfinGPIOFlagsASM ( ); int desired_bits = GPIO_value & SWITCHBITS; int LED_light_values = desired_bits >> 8; // Bits in wrong position WriteFlashLEDLights(LED_light_values); // to display on LEDS }

34 /25 Building a radio controlled car 4 Threads at least SWITCHES ON FRONT PANEL “INPUT COMMANDS: PROGRAMMABLE FLAGS FIO_FLAG_D Register YOUR PROGRAM RUNNING ON THE BLACKFIN LED LIGHTS ON FRONT PANEL “CONTROLSIGNALS TO RF TRANS: LED-CONTROLREGISTER EBIU INTERFACE ProcessDataASM( ) subroutine A/D D/A Interrupt routine D/A EAR PHONES A/DVOICE int ReadSwitches( )void WriteLED(int )

Blackfin BF533 I/O35 LEDs connected to FLASH port BACK FORWARD RIGHT LEFT ??? CONTROL ON Might be connected to other things DON’T CHANGE BEHAVIOUR