Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Computer Architecture and Assembly Language Assignment 4 - Prof. Baharloo, Assignments of Computer Science

Instructions for an assignment in computer science 230, focusing on computer architecture and assembly language. The assignment involves working with timers, interrupts, and leds using the c programming language. The objectives include writing functions for led control, implementing morse code, and manipulating duty cycles for led brightness.

Typology: Assignments

2022/2023

Uploaded on 04/04/2024

katie-grace
katie-grace 🇨🇦

1 document

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Page 1 of 7
Computer Science 230
Computer Architecture and Assembly Language
Spring 2024
Assignment 4
Due: Friday, April 5, 11:55 pm by Brightspace submission
(Late submissions not accepted)
Programming environment
For this assignment you must ensure your work executes correctly on the simulator
within Microchip Studio 7 as installed on workstations in ECS 249. If you have
installed Microchip Studio on your own then you are welcome to do much of the
programming work on your machine. (The IDE is available at no charge from
https://bit.ly/3llENk7 but comes only in the Microsoft Windows flavour.) You
must allow enough time to ensure your solutions work on the lab machines. If
your submission fails to work on a lab machine, the fault is very rarely that the lab
workstations. “It worked on my machine!” will be treated as the equivalent of “The
dog ate my homework!”
Individual work
This assignment is to be completed by each individual student (i.e., no group work).
Naturally you will want to discuss aspects of the problem with fellow students, and
such discussion is encouraged. However, sharing of code fragments is strictly
forbidden without the express written permission of the course instructor
(Baharloo). If you are still unsure regarding what is permitted or have other
questions about what constitutes appropriate collaboration, please contact me as
soon as possible. (Code-similarity analysis tools will be used to examine submitted
work.) The URLs of significant code fragments you have found and used in your
solution must be cited in comments just before where such code has been used.
Objectives of this assignment
Work with timers, interrupts and the LEDs using the C programming
language.
C programming language
In this assignment you will write several functions for a C language program. This
programs uses the LEDs on the lab boards (i.e., to keep this assignment simple, you
pf3
pf4
pf5

Partial preview of the text

Download Computer Architecture and Assembly Language Assignment 4 - Prof. Baharloo and more Assignments Computer Science in PDF only on Docsity!

Computer Science 230 Computer Architecture and Assembly Language Spring 2024

Assignment 4

Due: Friday, April 5 , 11:55 pm by Brightspace submission (Late submissions not accepted)

Programming environment

For this assignment you must ensure your work executes correctly on the simulator within Microchip Studio 7 as installed on workstations in ECS 249. If you have installed Microchip Studio on your own then you are welcome to do much of the programming work on your machine. (The IDE is available at no charge from https://bit.ly/3llENk7 but comes only in the Microsoft Windows flavour.) You must allow enough time to ensure your solutions work on the lab machines. If your submission fails to work on a lab machine, the fault is very rarely that the lab workstations. “It worked on my machine!” will be treated as the equivalent of “The dog ate my homework!”

Individual work

This assignment is to be completed by each individual student (i.e., no group work). Naturally you will want to discuss aspects of the problem with fellow students, and such discussion is encouraged. However, sharing of code fragments is strictly forbidden without the express written permission of the course instructor (Baharloo). If you are still unsure regarding what is permitted or have other questions about what constitutes appropriate collaboration, please contact me as soon as possible. (Code-similarity analysis tools will be used to examine submitted work.) The URLs of significant code fragments you have found and used in your solution must be cited in comments just before where such code has been used.

Objectives of this assignment

  • Work with timers, interrupts and the LEDs using the C programming language.

C programming language

In this assignment you will write several functions for a C language program. This programs uses the LEDs on the lab boards (i.e., to keep this assignment simple, you

will not need to use the LCD panel, and therefore need only work with a single C source file). The code given to you has already configured two of the mega timers (timers 1 and 3). Interrupt handlers for these timers are already provided (i.e., you are not being asked to implement interrupt handlers). A brief demonstration illustrating the behavior for each of the parts can be seen in this video:

https://youtu.be/rWHe6r2pI_

The assignment is in four parts, ordered from easier to more difficult, each part building upon your confidence in completing the previous part.

A. Write the code for lcd_state(). B. Write the code for SOS() which uses both your completed lcd_state() plus arrays with LED and duration data. C. Write the code for glow(). D. Write the code for pulse_glow().

There is also a bonus available for those who have successfully completed all four parts. It is called light_show() and is to implement the LED pattern shown on the YouTube video (link above).

The ZIP file distributed with this assignment contains a single directory consisting of an Micochip Studio C-language project. The skeleton file a4.c is also contained within this project directory. I have set the configuration of the project such that paths for both the compiler and build tools are correctly set for machines in the lab.

Part A: lcd_state()

This part of the assignment does not involve interrupts.

In assignment #2 you wrote an assembly-language function named leds_on. For this part you will write a function that accepts two parameters:

  1. The number of an LCD; and
  2. A number indicating the state to which that LCD must be put (with a zero value meaning “off”, and all other values meaning “on”).

The function is therefore to turn an LED on or off and immediately return.

To simply your work, your function need only deal with PORTL LEDs as numbered in the following diagram.

For example, at index 6 the bit pattern indicates LED #0 is turned on for 100 milliseconds).

So the twist is that you must cause the LEDs to flash appropriately for SOS by using these arrays: they already contain the patterns and durations required for SOS. You can use the arrays by writing a loop in which defined/declared appropriate counter variables, plus calls to led_state() and _delay_ms(). (A for-loop is perhaps a better choice here than a while-loop).

Part C: glow()

This part of the assignment must use the program-scope variable named count that is incremented by the timer 1 interrupt handler. When testing your solution, we will evaluate glow() separately from pulse_glow(), i.e., we will call one or the other function not both in the same test run.

Our current LEDs can be either on or off. There is, however, no easy way to set their relative brightness. Put differently, we control LED brightness by adjusting current through the LED, but we cannot adjust the current on our boards.

There is, however, another way to get something like a brightness control that exploits something called pulse-width modulation. In essence it means turning an LED on and off, doing so very rapidly, and in a way that gives the appearance of brightness or dimness.

Suppose we wish to have a somewhat dim LED. Consider the following diagram.

This shows that every 500 microseconds, the LED is turned on for 75 microseconds and then turned off for 425 microseconds. This cycle of 500 microseconds goes on for as long as dimmer LED intensity is needed.

And suppose we want a brighter LED, but not as bright as the fully-on LED. Consider the next diagram.

Now for 500 microseconds, the LED is turned on for 250 microseconds and then turned off for 250 microseconds.

So when the LED is on, we say the signal is high , and the time for which is the signal is high is called the on time. Given than our period here is 500 microseconds, our first diagram shows an on time of 75 microseconds, and the percentage of on time to the overall period is called the duty cycle (i.e., 75/500 = 0.15 = 15% duty cycle). For our second diagram, the duty cycle is 50% (i.e., 250/500 = 0.5 = 50% duty cycle). Going further, a duty cycle of 0% would be an LED that is completely off, while a duty cycle of 100% would be an LED that is completely on.

You are to implement this notion of a duty cycle. Function glow() takes two parameters:

  1. The number of an LCD; and
  2. The duty cycle for that LCD expressed as a floating-point value between 0. and 1.0.

In order to implement this function, you must use an infinite loop, and therefore you will only be able to ever set the glow for a single LED. The infinite loop will take advantage of the fact that the global variable count is incremented once a microsecond. The loop’s form will most likely need to be somewhat similar to:

threshold = PWM_PERIOD * given duty cycle do forever { if (count < threshold and LED is not already on) { turn the LED on; } else if (count < PWM_PERIOD and LED is not already off) { turn the LED off; } else { /* count must be greater than PWM_PERIOD */ count = 0; turn the LED on; } }

Note that PWM_PERIOD is given in the top-most “DO NO TOUCH” section of a4.c.

Warning: Even though we might expect the LEDs to respond in a visually linear fashion as we change the duty cycle, unfortunately our own visual systems do not respond in a similar way. That is, the differences in brightness that we see as

Evaluation

  • 4 marks: Solution for part A
  • 4 marks: solution for part B
  • 6 marks: solution for part C
  • 6 marks: solution for part D
  • 2 marks: solution for the bonus

The total mark for this assignment is 20 (i.e., if full marks are given for parts A, B, C and D, and the bonus is correctly implemented, the mark will be 22/20).

Some of the evaluation will also take into account whether or not submitted code is properly formatted (i.e., indenting and commenting are suitably used), and the file correctly named.