



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 7
This page cannot be seen from the preview
Don't miss anything!
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
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:
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:
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
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.