
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://wiki.hh.se/ceres/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.hh.se/ceres/index.php?action=history&amp;feed=atom&amp;title=PA_8001_2013_Practical_1</id>
		<title>PA 8001 2013 Practical 1 - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.hh.se/ceres/index.php?action=history&amp;feed=atom&amp;title=PA_8001_2013_Practical_1"/>
		<link rel="alternate" type="text/html" href="https://wiki.hh.se/ceres/index.php?title=PA_8001_2013_Practical_1&amp;action=history"/>
		<updated>2026-05-10T03:35:39Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.22.6</generator>

	<entry>
		<id>https://wiki.hh.se/ceres/index.php?title=PA_8001_2013_Practical_1&amp;diff=2958&amp;oldid=prev</id>
		<title>Slawek: Created page with &quot;== Objectives ==  There are three objectives for this practical:   * Experiment with concurrency (without any underlying support) and observe its issues  * Apply the concepts ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.hh.se/ceres/index.php?title=PA_8001_2013_Practical_1&amp;diff=2958&amp;oldid=prev"/>
				<updated>2014-06-23T09:21:18Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Objectives ==  There are three objectives for this practical:   * Experiment with concurrency (without any underlying support) and observe its issues  * Apply the concepts ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Objectives ==&lt;br /&gt;
&lt;br /&gt;
There are three objectives for this practical: &lt;br /&gt;
&lt;br /&gt;
* Experiment with concurrency (without any underlying support) and observe its issues&lt;br /&gt;
&lt;br /&gt;
* Apply the concepts of busy waiting for reading inputs&lt;br /&gt;
&lt;br /&gt;
* Get more insight into the working of the AVR Butterfly board, particularly with respect to timing and output&lt;br /&gt;
&lt;br /&gt;
== Instructions ==&lt;br /&gt;
&lt;br /&gt;
Submit a single .zip file on blackboard with four folders, each containing the solutions to the below-specified parts. &lt;br /&gt;
&lt;br /&gt;
For each function in the code, you need to write a piece of comment, describing its pre- and post-condition and one or more test-cases. &lt;br /&gt;
&lt;br /&gt;
In order to make the on-board processor run at its maximum speed, its CPU clock prescaler functionality must be disabled. &lt;br /&gt;
This is achieved by writing the byte values 0x80 followed by 0x00 to the special register CLKPR when your program starts up. &lt;br /&gt;
See the [[media:ATmega169Manual.pdf|ATmega169 manual]], pages 29-31, for further info.&lt;br /&gt;
&lt;br /&gt;
=== Part 1: Prime Numbers ===&lt;br /&gt;
&lt;br /&gt;
Write a C program for displaying numerical digits on the LCD of the Butterfly board. &lt;br /&gt;
Use the same LCD configuration as in exercise 3 of [[PA 8001 2013 Practical 0|Practical 0]] (except that you might want to use default wave form instead of lowpower). &lt;br /&gt;
Your function should have signature&lt;br /&gt;
&lt;br /&gt;
 void writeChar(char ch, int pos)&lt;br /&gt;
&lt;br /&gt;
and should work properly for characters 0,1,2,3,4,5,6,7,8,9 (digits), &lt;br /&gt;
we are not interested in displaying other ASCII characters. &lt;br /&gt;
&lt;br /&gt;
Your function should turn on the segments needed for displaying the digits in any of the possible 6 positions. &lt;br /&gt;
Use 0, 1, 2, 3, 4 or 5 to number the positions (called 2, 3, 4, 5, 6 and 7 in the documentation of the LCD). For other values of pos your function should do nothing.&lt;br /&gt;
&lt;br /&gt;
When you have verified that individual digits can be properly displayed at the desired position, write a function&lt;br /&gt;
 void writeLong(long i)&lt;br /&gt;
that uses writeChar with a proper position value for each of the digits of i. &lt;br /&gt;
In case the i has more than 6 digits, your function should only display the six least significant digits.&lt;br /&gt;
&lt;br /&gt;
Finally, demonstrate your LCD driver by implementing a program that continuously computes increasing prime numbers and prints them on the display. &lt;br /&gt;
The prime numbers can be computed in the simplest possible way: a long variable is incremented for each turn in a loop, and a helper function&lt;br /&gt;
&lt;br /&gt;
 int is_prime(long i)&lt;br /&gt;
&lt;br /&gt;
is called to determine whether the value is a prime number that has to be printed. &lt;br /&gt;
The initial value for this variable can be any value you find meaningful. Implementing is_prime(i) could be done by computing i % n (i.e., the remainder from division i/n) for all 2 &amp;lt;= n &amp;lt; i, and &lt;br /&gt;
returning false (0) if any such expression is 0, true (1) otherwise. Wrap up you solution in a function&lt;br /&gt;
&lt;br /&gt;
 void primes()&lt;br /&gt;
&lt;br /&gt;
that is called directly from main() after device initialization.&lt;br /&gt;
&lt;br /&gt;
=== Part 2: Marquee ===&lt;br /&gt;
&lt;br /&gt;
The second task is to write a program that makes the illusion of a moving symbol at the topmost part of the LCD (symbols S1 to S5) of the LCD.&lt;br /&gt;
This is performed by turning on and off the segments in an interleaving and circular fashion with a steady frequency of 1 Hz (a Hz is 1/second). &lt;br /&gt;
This means that a segment is turned on during half a second and off during half a second, and &lt;br /&gt;
then the next segment is turned on as long as the program is running. &lt;br /&gt;
&lt;br /&gt;
For timing purposes you will do busy waiting with the 16-bit Timer/Counter1 unit. &lt;br /&gt;
Details of this device can be found in pages 95-123 of the [[media:ATmega169Manual.pdf|ATmega169 manual]]; &lt;br /&gt;
however, most of this information is beyond the scope of this assignment. &lt;br /&gt;
All we will need is a continuously running timer that can be read at any time and doesn't wrap around too often. &lt;br /&gt;
A suitable configuration is to let Timer/Counter1 use the 8 MHz system clock with a pre-scaling factor of 256, &lt;br /&gt;
this should make the 16 bits in register TCNT1 wrap around approximately every 2.1 seconds. &lt;br /&gt;
The only register whose default values need to be changed in order to achieve this is TCCR1B.&lt;br /&gt;
&lt;br /&gt;
Concretely, this program should maintain an unsigned integer variable representing the next timer value to wait for, and &lt;br /&gt;
use busy-waiting to stop execution until register TCNT1 has reached that value. Note that turning the display on and off requires updating in two phases, &lt;br /&gt;
that preferably last half the desired period. &lt;br /&gt;
Note also that some special measures need to be taken to ensure proper operation when the timer wraps around to zero.&lt;br /&gt;
&lt;br /&gt;
Wrap up you solution in a function&lt;br /&gt;
&lt;br /&gt;
  void marquee()&lt;br /&gt;
&lt;br /&gt;
that is called directly from main() after device initialization.&lt;br /&gt;
&lt;br /&gt;
=== Part 3:  Joystick ===&lt;br /&gt;
&lt;br /&gt;
The third part of this assignments is about dealing with external input. &lt;br /&gt;
The task is to write a program that moves a symbol in the bottom row to right or left each time the joystick is moved to that direction and released. &lt;br /&gt;
The joystick is connected to certain bits of I/O ports B and E; &lt;br /&gt;
here it is recommended that bits 2 and 3 of port E are used, &lt;br /&gt;
which corresponds to right and left movement of the joystick.&lt;br /&gt;
&lt;br /&gt;
Details on how to operate the I/O ports are given in pages 55-78 of the [[media:ATmega169Manual.pdf|ATmega169 manual]]; &lt;br /&gt;
however, as with the section on 16-bit timers, most of this information is beyond the scope of the assignment. &lt;br /&gt;
What is necessary to know is that the I/O ports can function as both inputs and outputs, and &lt;br /&gt;
that the output register for port x (PORTx) controls pull-up resistors for the input register of port x (PINx) whenever port x is configured for input &lt;br /&gt;
(the latter is controlled individually for each bit of port x by the settings in register DDRx). &lt;br /&gt;
All ports are configured as inputs by default, but in order to obtain proper operation of the joystick switches, &lt;br /&gt;
the pull-up resistors must be activated for the corresponding pins. For our purposes, this amounts to setting bits 2 and 3 high in register PORTE during program initialization.&lt;br /&gt;
&lt;br /&gt;
The program should be implemented using busy-waiting for changes on bits 2 and 3 in register PINE. &lt;br /&gt;
Notice that the joystick switches are active low, which means that they will cause a 0 in the input bit position as long as the switch is pressed, and a 1 otherwise.&lt;br /&gt;
&lt;br /&gt;
Wrap up you solution in a function&lt;br /&gt;
&lt;br /&gt;
 void button()&lt;br /&gt;
&lt;br /&gt;
that is called directly from main() after device initialization.&lt;br /&gt;
&lt;br /&gt;
=== Part 4: Concurrency === &lt;br /&gt;
&lt;br /&gt;
The final part of the assignment consists of putting all the previous parts together as one single application. &lt;br /&gt;
This will require some modifications to your existing code, and &lt;br /&gt;
the purpose of this part is specifically to draw your attention to these modifications.&lt;br /&gt;
&lt;br /&gt;
Use the simple technique explained  in lecture 2: the cyclic execution and interleaving by hand. &lt;br /&gt;
In order to compare with later implementations, you will not be allowed to modify any of your existing functions, &lt;br /&gt;
instead you should create new copies of any functions that needs to be changed.&lt;br /&gt;
&lt;br /&gt;
Try out your program for different start values for the prime number computations, &lt;br /&gt;
for example 1, 5000, and 25000. &lt;br /&gt;
&lt;br /&gt;
How do these values affect the display of the marquee?  &lt;br /&gt;
&lt;br /&gt;
How is the response time of the joystick affected? &lt;br /&gt;
&lt;br /&gt;
What would it take to ensure a stable marquee and &lt;br /&gt;
a responsive joystick, that are independent of the currently calculated prime number?&lt;br /&gt;
Implementing your solution and showing that it works will lead to a bonus point. &lt;br /&gt;
(If you would like to get the bonus put a separate folder called &amp;quot;bonus&amp;quot; in which your solution is implemented.)&lt;br /&gt;
  &lt;br /&gt;
Write a short text explaining the issues encountered and a possible solution. &lt;br /&gt;
Include all the programs and the short report (in pdf) in the zip file under the folder Part 4.&lt;br /&gt;
&lt;br /&gt;
== [[PA 8001 Ed 2013|Back to Embedded Systems Programming]] ==&lt;/div&gt;</summary>
		<author><name>Slawek</name></author>	</entry>

	</feed>