Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Suppose, you are an intern at Toyota, where your assignment is to design the

ID: 3599301 • Letter: 1

Question

1) Suppose, you are an intern at Toyota, where your assignment is to design the Mileage unit for Toyota Prius 2018’s dashboard (Fig. 1). In this task, you will be building a fully custom Mileage circuit unit.

A) Utilizing VisUAL ISA write assembly language version of the following draft pseudo-code to implement the Mileage unit and emulate it.

while (mps>0)

                load and increase odometer reading

                load and decrease fuel reading //every 28 mile subtract one gallon

                if (gallons < =1) prompt user //store FFFF in Zero register

// Also assume MPS (Mileage Per Second), Odometer Reading and Fuel Reading can be found in SP(0), SP(1), and SP(2) and initial values are 5 MPS, 11427MI and 13 Gallons respectively.

B) According to your implementation in T1 (A), what would be the odometer reading after 10th iteration of the loop. (show screenshot)

ODO MPH 42

Explanation / Answer

volatile uint8_t tick; // ++ every 4mS
uint8_t tickX;

uint8_t time4mS;
uint8_t time100mS;
uint32_t time1S;


#define TX_BUF_SIZE 64
#define TX_BUF_MASK 0x3F

#define RX_BUF_SIZE 64
#define RX_BUF_MASK 0x3F

volatile char txBuf[TX_BUF_SIZE];
volatile uint8_t txBufInPtr;
volatile uint8_t txBufOutPtr;

volatile char rxBuf[RX_BUF_SIZE];
volatile uint8_t rxBufInPtr;
volatile uint8_t rxBufOutPtr;

char cmdBuf[16];
uint8_t cmdBufPtr;

volatile uint16_t servo[4];

volatile uint8_t servoState;

#define S_HIGH 35000
#define S_LOW 45000
#define CENTER 40000

uint8_t stateA;
uint8_t stateB;
uint8_t stateC; // run servos

uint8_t sspeed;


SIGNAL(USART_UDRE_vect){
if(txBufOutPtr == txBufInPtr){
// no more char to output
UCSR0B &= ~0x20;
} else {
// we have more
UDR0 = txBuf[txBufOutPtr++];
txBufOutPtr &= TX_BUF_MASK;
}
}

SIGNAL(USART_RX_vect){
rxBuf[rxBufInPtr++] = UDR0;
rxBufInPtr &= RX_BUF_MASK;
}

SIGNAL(TIMER1_OVF_vect){
TCCR1B = 0x00; // kill timer1
  
switch(servoState){
case 0:
PORTD &= ~0x10; // kill servo 0
PORTD |= 0x20; // start servo 1

TCCR1A = 0x00;
TCNT1 = servo[1];
TIMSK1 = 0x01; // interrupts for timer 1 on
TCCR1B = 0x01; // start counting
servoState = 1;

break;

case 1:
PORTD &= ~0x20; // kill servo 1
PORTD |= 0x40; // start servo 2

TCCR1A = 0x00;
TCNT1 = servo[2];
TIMSK1 = 0x01; // interrupts for timer 1 on
TCCR1B = 0x01; // start counting */
servoState = 2;

break;
  
case 2:
PORTD &= ~0x40; // kill servo 1
break;
  
}
}


void inline processServos(){ // this is called every 20mS
PORTD |= 0x10;
servoState = 0;
TCCR1A = 0x00;
TCNT1 = servo[0];
TIMSK1 = 0x01; // interrupts for timer 1 on
TCCR1B = 0x01; // start counting
  
}

SIGNAL(TIMER0_COMPA_vect){
static uint8_t i = 0;
PINC = 0x08;
tick++;
i++;

if(i > 4){
PINC = 0x10;
i = 0;
processServos();
}

}


void busyWait(){
volatile uint32_t i;
for(i=0;i < 400000; i++){
}
}

void outCharOld(char c){
while((UCSR0A & 0x20) == 0); // we don't want to do this
UDR0 = c;
}

void outChar(char c){
txBuf[txBufInPtr++] = c;
txBufInPtr &= TX_BUF_MASK;
UCSR0B |= 0x20;
}

void printHex4(uint8_t n){
n = n & 0x0F;
n = n + '0';
  
if(n > '9'){
n += 7;
}

outChar(n);
}

void printHex8(uint8_t n){
printHex4(n >> 4);
printHex4(n);
}

void printHex16(uint16_t n){
printHex8(n >> 8);
printHex8(n);
}

void printHex32(uint32_t n){
printHex16(n >> 16);
printHex16(n);
}

void printStatus(){
printHex8(rxBufInPtr);
outChar(' ');
printHex32(time1S);
outChar(0x0A);
}

void printString(char *s){
while(s[0]){
outChar(s[0]);
s++;
}
}