Presentation is loading. Please wait.

Presentation is loading. Please wait.

Thermal arm-wrestling

Similar presentations


Presentation on theme: "Thermal arm-wrestling"— Presentation transcript:

1 Thermal arm-wrestling
Design of a video game using two programmable flags (PF) interrupts Hardware interrupts

2 Problem to be solved Customer game concept
I WIN YOU WIN Has two sensors and a ready signal At the ready signal – the two players have to use bio-feedback to move the cursor into the winning area Three play modes One person player – moves the cursor with one sensor One person player – controls the cursor with two sensors sort of EXO-Sketch mode Game mode – two players Sensor reading is determined by the difference in temperature NOW compared to the temperature at the ready signal 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

3 Customer game plan Player1_TemperatureNow, and Player1_TemperatureStart Ditto player 2 While not started { Determine Player1 Temperature, Player2 temperature Update Game Screen with start information } Cursor is centered – update Game screen While nobody has won { Determine Player1 Temperature, Player2 temperature Determine Player1, player2 difference in temperature if player1 difference larger then cursor- - else cursor ++ Update Game screen Determine if somebody has won } Display winning message 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

4 Concept Use TDD approach
Main task – calculating / updating cursor and display 2nd task -- 1 sensor on PF10 – 33 Hz signal – need to measure periods of high and low signal to determine temperature. 3rd task -- Second sensor on PF11. Long term goal -- average of 30 values every second. That’s 2 seconds of processing every second if done by normal programming Possible solution – use the PF signals to generate interrupts on high/low and low/high transitions and read core time value. Use the core timer values to determine a temperature Discussed and tested in this class – handling the two PF signals which both cause the SAME interrupt signal 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

5 Redesigned Tests needed
Show we can link thermal test code to main( ) Show CoreTimer and LED functions are still working. Show we can handle a single PF interrupt (software interrupt) Show we can use a single PF interrupt to calculate a temperature. Show how we can set up the PF11 interrupt in hardware Do same thing for other PF10 interrupt Handle two PF interrupts at the same time to calculate temperature Demo full solution using LED display to show cursor movement – but code so that can upgrade to more lights or LCD screen when becomes available. Show we can store a series of time readings in an array DONE FOR SOFTWARE INTERRUPTS Demo simplified final version Show we can calculate the temperature from timer reading array – calculate average of 30 on each sensor 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

6 1 -- Build test to show we can link to new project from main( )
Attempt to track down the reason for Tests being run when not planned int Connect_ThermalVideoGameTests(int level); static bool valid_test_request = false; static int wanted_test_level = 0; int Connect_ThermalVideoGameTests(int level) { valid_test_request = true; wanted_test_level = level; } 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

7 2 -- Build test to show Core Timer and LED functions are still working
Activate the Core Timer test code from before Activate LED test code from before (Lab. 2). Show only failed tests // Run all the required tests Connect_ClassTimerDemo(0xFF); Connect_ThermalVideoGameTests(0x0); Connect_instructortestsLED_Lab2Part1(0xFF); 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

8 Issues when developing interrupt driven code
All of the following must work for your code to work Main task Interrupt task Setting up the interrupt hardware registers Connecting to external events that cause interrupts All are interlinked – making it difficult to determine what part of the code (a DEFECT) is causing the problem One approach is to first test the main task with “software interrupts” so that the “uncontrollable” external event becomes a “controllable” internal event – “raise(ik_ivg12)” from <signal.h> 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

9 3 – Test for handling a single PF interrupt using a software interrupt test
Similar to Core timer Interrupt Syntax “raise( )” forces a software interrupt of type ik_ivg12 (PF) Will need to worry about hardware setup later 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

10 4 – Fixing the Test code error
12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

11 4B Calculate a temperature test
Fake the down-up-down of temperature Sensor Long times to make loop more accurate Expected accuracy issues Had to print 0ut values to check 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

12 5 – Need to handle the “true PF registers” to generate a hardware interrupt
Functions needed unsigned long int SetPFInterruptsASM( ??) Returns old interrupt settings Set new settings void StartPFInterruptsASM(???) void StopPFSettingsASM(???) Hardware information Chapter 14 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

13 PF registers Direction, Data, Polarity and Enable all from Lab. 2
Flag Mask registers – 14-11 Flag mask Interrupt data register – basically which PF pins have been set to allow to cause interrupt Flag mask Interrupt Set register – sets PF pin that is allowed to cause an interrupt, without the need for a read – or mask – write operation Flag Mask Interrupt Clear register – which PF pin is no longer allowed to cause an interrupt without the need for a read – and mask – write operation Flag interrupt Sensitivity register (FIO_EDGE) – set for edge-sensitive – also need FIO_BOTH 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

14 5 – Need to handle the “true PF registers” to generate a hardware interrupt
unsigned long int SetPFInterruptsASM ( ushort whichPFinterrupts) Returns old interrupt settings Sets PF pins can cause edge sensitive interrupts Plan ahead -- May want to set both PF10 and PF11 interrupts later void StartPFInterruptsASM(void) already exists as register_handler(ik_ivg12, PFInterruptHandler); void StopPFSettingsASM(ushort whichPFinterrupts) Lets just stop all IVG12 interrupts When PF11 interrupt occurs – the PF11 bit in the data register (FIO_FLAG_D) is set – this must be cleared using FIO_FLAG_C (clear data register). This clears the bit without the need to do a read – and mask – write operation. 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

15 6 – Build a test to show that write the needed code (in ASM) to set up the PF interrupts
Registers described in Chapter 14 Stop all interrupts for the moment – CLI instruction Need to set FIO_MASKA_D bits 1 Write only needed if “set” using FIO_MASK_S register Need to set FIO_POLAR for active rising edge – Lab 2 code 1 read – then mask – then 1 write Need to set FIO_INEN (R – mask – W) Need to set FIO_DIR (R – mask – W) Need to clear FIO_FLAG_D so that don’t think interrupt already happened (1W if use FIO_FLAG_C register approach)) Need to set FIO_EDGE and FIO_BOTH (2R – mask 2W) Restart interrupts – STI instruction – but with PF interrupt stopped Possibility that missing stuff since first time tried this 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

16 6B – Need to build a test to show that can stop interrupts
Need to clear FIO_MASKA_D register bits Single write operation if use special FIO_MASKA_C bit Possibility that missing stuff since first time tried this 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

17 First Test for Set up PF interrupts
12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

18 Write code to satisfy tests Run the tests – complete system hang
Test Level 1 Never returns 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

19 Need to do code review After fixing the error – get this result
Check code – need to return old interrupt level FIO_MASKA_D – that requires a read that I had not designed in – change the test 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

20 Move onto setting FIO_FLAG registers
12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

21 Check Ability to turn off PF interrupts
12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

22 Test for interrupts using switches
PF interrupts active NOTHING HAPPENING SYSTEM IS HUNG 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

23 Turns out – missing stuff in set up
IMASK -- Page 4-33 Global register – allows IVG12 interrupts to occur SIC_IMASK – Page 4-28 System interrupt mask – especially for peripheral devices Enabling PF Interrupt A during SetUpPFInterrupts( ) fixed the problem of getting INTO interrupts – but the function never came out BECAUSE Bit 11 of FIO_FLAG_D MUST BE CLEARED inside interrupt service routine – clearing the interrupt bit!!!!!! 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

24 Some other interesting things uncovered during Testing
I wanted to do the same test as during Software Interrupt test At each interrupt – place core timer values into an array Read through the slides yourself 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

25 9 -- Build test to show we store time values into an array
Array “not in Blackfin memory” 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

26 9 -- Look under local variables
window shows things on C++ stack Values look like they counting up rather than counting down Also only went around loop 5 times not 2 * 5 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

27 Something should change
9 -- Fixed loop size, incremented COUNT / PERIOD, incremented UseFixedTimeASM( ) Something should change Still the same 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

28 9 -- Improve the test – initial array = 0;
Prototype long int Need ulong Timer Values not zero 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

29 9 -- Suspicion – switch to debug mode
works !!!! 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

30 9 -- Back to release mode DEAD CODE REMOVED NO ARRAY HANDLING
12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

31 9 -- Need to “ScareCompiler” to use array
2 WRITE 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

32 10A -- Build test to show we can calculate the temperature from the timer array
12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

33 10A – Code for splitting the array
4 errors made 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

34 10B – CalculateAverage( ) and CalculateTemperature( ) – Tests and code
1 syntax 2 typos 1 logical 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada

35 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. 12/1/2018 Thermal Arm Wrestling, Copyright M. Smith, ECE, University of Calgary, Canada


Download ppt "Thermal arm-wrestling"

Similar presentations


Ads by Google