Assignment 3

Peter Harrison and Calvin Huo

Questions 0, 7 and 8

Calvin Huo’s Question 0 and Answers

Question 0
[A] – Suppose we have two thermo sensors instead of one thermo sensor for lab three which are both brought in on different lines. New code is given to the blackfin to process the difference in temperature. One sensor acts as a reference point to the other value. Considering that we are restrained to using the Blackfin’s LED to display temperature what advantages can we get for using two thermo sensors over one and how does this affect task procedures?

[B] – To help, two switches are used for user input. If both switches are low the program performs the normal difference operation between the two temperatures. If the first switch is high while the second switch is low, the reference temperature is displayed on the LCD and the reverse (first switch low, second switch high) displays the measuring temperature. If both are high, then it stores the result to some memory location for other subroutines to use (assume maximum of 10 data)
In any case, if the measured difference is too large (not enough LEDs to display the value) or if the difference is negative, the LED simply flashes at a steady rate until a displayable value is shown. (When both switches are high the difference is still stored regardless of the maximum displayable value).

Create code for a new DisplayTempuratureLED and CalculateTempurature that follows the above design. Assume MeasureTiming() exists and performs the necessary data processing for T1 and T2.

Question 0 Answers

[A] This is very open ended. There are many answers and is more of a way to gear up for part b.

Some Possible Advantages:

- Higher temperature value can be measured and displayed since we have a reference temperature to add to displayed value

- Help check for uniform temperature distribution

- Compete against another person to determine who is hotter

Task Scheduling problems:

- if we had two separate calculating functions, one might lag behind and the results would be off

- Otherwise no real noticeable affect in scheduling since the extra lines of code will far too fast to be noticeable

[B]

short int Tempurature1, Tempurature2; //Temperatures calculated from CalculateTempurature

short int DisplayTemp; //Temperature to display

short int StoredTemp[10];

short int NumStored = 0;

short int T11, T12

short int T21, T22; //Two sets since there are two thermo sensors

//Not shown is MeasureTiming which modifies T1,T2 with the correct data from sensors

void DisplayTempuratureLED() {

#define switch3 0x0400

#define switch4 0x0800

short int Switches = readGPIOFlagsASM();

short int sw3 = Switches & switch3;

short int sw4 = Switches & switch4;

if ((sw3!=switch3) & (sw4!= switch4))

DisplayTemp = Tempurature1 – Tempurature2;

else if ((sw3!=switch3) & (sw4==switch4))

DisplayTemp = Tempurature2;

else if ((sw3==switch3) & (sw4!=switch4))

DisplayTemp = Tempurature1;

else if ((sw3==switch3) & (sw4==switch4))

if (NumStored < 10) {

DisplayTemp = Tempurature1 – Tempurature2;

StoredTemp[NumStored] = DisplayTemp;

NumStored++;

}

if (DisplayTemp > 31 || DisplayTemp < 0)

FlashAllLEDs();

else

WriteFlashLEDASM(DisplayTemp);

}

void CalculateTempurature() {

Tempurature1 = 235 – ((400*T11)/T12);

Tempurature2 = 235 – ((400*T21)/T22);

}

Peter Harrison’s Question 0 and Answers

Q0.

A. An ENCM 511 student was working on lab 4 when he came across an error. Although all of his code compiled and he was able to run his program, his LCD screen did not output any data.

Through some clever thinking and the use of breakpoints, he was able to diagnose the problem as occurring somewhere in the following lines. What is the student doing wrong such that the LCD screen won’t output any data? Assume that any functions or variables not defined here are defined elsewhere. (1 mark)

InitLCD() {

#define RS_COMMAND 0x400 //RS line low (switch 10)

#define E_LINE_HIGH 0x100 // switch 8 line high

#define E_LINE_LOW 0x000 //switch 8 line low

#define E_LINE_ON = RS_COMMAND | E_LINE_HIGH | 0x30

#define E_LINE_OFF = RS_COMMAND | E_LINE_LOW | 0x30

static short int MyMessage [] = {E_LINE_ON, E_LINE_OFF, E_LINE_ON, E_LINE_ON, E_LINE_OFF, E_LINE_ON}

if(SPI_MessageCanBeSent_G == 0) return;

SPI_MessageSize_G = 0;

SPI_Message_Size_G = 6;

for (int count = 0; count <SPI_MessageSize_G; count++)

SPI_Message[count] = MyMessage[count];

pleaseSendSPIMessage = 1;

}

B. Having discovered his issue, the student found that his program was very slow. He had recently read about something called DMA which could vastly improve his program’s run speed. Rewrite the program above to make use of a pre-made DMA function called SuperMemoryMover(int *source, int *dest, int size) and give a brief summary as to why this might speed up the student’s code if placed here and in other places in the scheduler tasks. (4 marks)

ANSWERS

A. The student correctly did all but one thing. In his definitions, he defined RS_COMMAND as being on, when in fact he wanted it off. this caused “data” data to be sent to the LCD instead of command data.

B. to use the SuperMemoryMover function, replace the for loop in InitLCD with SuperMemoryMover(MyMessage, SPI_Message, SPI_Message_Size_G). DMA is faster in this case because it cuts down on the use of the processor and allows DMA to transfer the data in the background. Since this data is going from one data location to another, it is a faster transfer than using the processor.

Q. 7

Q7 Burglar Alarm

A. As per the design layout, line AA is connected to PF0, line CC is connected to PF1, line BB is connected to PF2, and DD is connected to PF3.

In addition, XX is connected to PF4, WW is connected to PF5, ZZ is connected to PF6, and YY is connected to PF7.

B.

void WaitForIntruder(void) {

ActivateInterface();

WritePFInterface(0x60); //This activates PF5 and 6, which match up with the lines //relating to C and B respectively.

int nopress = 1;

int readvalue;

while(nopress ==1){

readvalue = ReadPFInterface()

if(readvalue == 0x0A || 0x08 || 0x02)

return;

}

C.

IMASK / 0x0000 1000 / FIO_FLAG_S / FIO_DIR
SIC_IMASK / 0x0018 0000 / FIO_EDGE / FIO_POLAR / 0x000A
ILAT / 0x0000 1000 / FIO_BOTH / TCOUNT
TPERIOD / TSCALE / FIO_MASKA_D / 0x000F
FIO_FLAG_D / FIO_INEN / PF_STATUS_D

Q. 8

[A]

void Wait ( ) {

#define Pin0Mask 0x01

#define Pin7Mask 0x80

while ( 1 ) {

short int CurrentPins = ReadGPIO();

short int IsPin0 = CurrentPins & Pin0Mask;

short int IsPin7 = CurrentPins & Pin7Mask;

if (IsPin0 == Pin0Mask)

PF0Stuff(); //It says Pin0Stuff() but earlier it was called PF0Stuff() and i have

decided to go with the earlier

if (IsPin7 == Pin7Mask)

PF7Stuff(); //Same reasoning as for PF0stuff()

int Counter = 0;

}; //Assuming infinite loop, it does not mention any exit conditions

}

.global _Wait

_Wait:

LOOPTOP:

MOVE.B D0, 0

CALL _ReadGPIO

MOVE.B D1, D0 //Copy value in D0 to D1

AND.B #01, D1 //Use D1 as bit 0 indicator

CMP.B D1, #01

BNE NEXT1

CALL _PF0Stuff

NEXT1:

AND.B #80, D0 //Reusing R0 since we don't need it anymore

CMP.B D0, #80 //Use D0 as bit 7 indicator

BNE NEXT2

CALL _PF7Stuff

NEXT2:

JUMP LOOPTOP

RTS

[B]

void Poll ( ) {

#define Pin0Mask 0x01

#define Pin7Mask 0x80

while ( 1 ) {

short int CurrentPins = ReadGPIO();

short int IsPin0 = CurrentPins & Pin0Mask;

short int IsPin7 = CurrentPins & Pin7Mask;

if (IsPin0 == Pin0Mask)

PF0Stuff(); //It says Pin0Stuff() but earlier it was called PF0Stuff() and i have

decided to go with the earlier

if (IsPin7 == Pin7Mask)

PF7Stuff(); //Same reasoning as for PF0stuff()

int WaitAWhileCount = 0;

while(WaitAWhileCount < 100)

WaitAWhileCount++; //I would perfer to put the system into low power mode, for

some time but I don't know how that would look in M68K

}; //Assuming infinite loop, it does not mention any exit conditions

}

.global _Poll

_Wait:

LOOPTOP:

MOVE.B D0, 0

CALL _ReadGPIO

MOVE.B D1, D0 //Copy value in D0 to D1

AND.B #01, D1 //Use D1 as bit 0 indicator

CMP.B D1, #01

BNE NEXT1

CALL _PF0Stuff

NEXT1:

AND.B #80, D0 //Reusing R0 since we don't need it anymore

CMP.B D0, #80 //Use D0 as bit 7 indicator

BNE NEXT2

CALL _PF7Stuff

NEXT2:

MOVE.B D0, 0

WAITAWHILELOOP:

ADD.B #1, D0

CMP.B #100, D0

BNE WAITAWHILELOOP //Exits loop if IT DOES equal 100, otherwise jump back up

JUMP LOOPTOP

RTS

//Difference between Poll and Wait is the interval of checks.

//Wait will keep checking consuming power constantly

//Poll will wait a while in low power mode to lessen power consumption

[C]

.byte4 ClockCount

.global _ClockSignal_ISR

_ClockSignal_ISR:

MOVE.W D0, #ClockCount

ADD.W #1, D0

MOVE.W #ClockCount, D0

RTE