1 – Timer Interrupts [50 pts]
In this problem, you will create a PWM waveform with a specific duty cycle value using the
microcontroller system with timer unit and interrupt description given in file “datasheet_for_q1”:
• The microcontroller is an 8-bit system and its clock runs at 8MHz.
• The timer is also 8-bit.
• The timer uses only the internal clock and there are 3 predefined pre-scale values:
o 1: No pre-scaling
o 8: System clock/8
o 64: System clock/64
• There are two modes of the timer:
o Normal Mode: The timer counts up to the MAX value and then restarts from the
BOTTOM (where MAX=maximum value that an 8-bit counter can go up to and
BOTTOM=0).
o Clear on Compare (CTC) Mode: The timer counts up to the TOP value (defined by
the OCRA register) and then restarts from the BOTTOM (=0).
• The registers in the timer unit are as follows:
o TCNT: Keeps the count value of the timer.
o OCRA: Keeps the output compare value A.
o OCRB: Keeps the output compare value B.
o TCR: Controls the modes and properties of the timer/counter. The layout of the
individual bits and how they can be controlled are shown below:
TCR:
7th bit 6th bit 5th bit 4th bit 3rd bit 2nd bit 1st bit 0th bit
COMPB COMPA OVF OCIA OCIE TM PS1 PS0
• The first two bits, PS1 and PS0 are used for pre-scaling:
o PS1 = 0, PS0 = 0: Timer is off.
o PS1 = 0, PS0 = 1: No pre-scaling (i.e. pre-scale value = 1).
o PS1 = 1, PS0 = 0: Pre-scale value = 8.
o PS1 = 1, PS0 = 1: Pre-scale value = 64.
o And setting a pre-scalar value starts the timer.
• TM bit is used to set the timer mode.
o TM = 0: Normal mode.
o TM = 1: CTC mode.
• OVF bit is used to see if the timer overflows. This bit is set to 1 whenever the TCNT value
goes over MAX and becomes 0. If you do not use interrupts, this bit does not clear
automatically, i.e. it needs to be cleared manually by setting it to 0.
• COMPA bit is used to see if the timer value matches the OCRA register value. If TCNT
becomes equal to OCRA, COMPA value becomes 1. If you do not use interrupts, this bit
does not clear automatically, i.e. it needs to be cleared manually by setting it to 0.
• COMPB bit is used to see if the timer value matches the OCRB register value. If TCNT
becomes equal to OCRB, COMPB value becomes 1. This bit needs to be cleared manually
by setting it to 0.
COMPE375 Exam3 – 3
• OCIE bit, when set to 1, enables the timer overflow interrupt. If enabled, whenever the
TCNT value goes over MAX and becomes 0, the ISR, with the “Timer_OVF_vect”
interrupt vector name is called. Also, this way, the OVF bit is automatically cleared, i.e.
you do not have to manually clear it.
• OCIA bit, when set to 1, enables the OCRA compare interrupt. If enabled, whenever the
TCNT value matches the OCRA register, the ISR, with the “Timer_OCRA_vect” interrupt
vector name is called. Also, this way, the COMPA bit is automatically cleared, i.e. you do
not have to manually clear it.
• You should not make any assumption about the initial values of the bits in the TCR register.
Interrupt-related system details:
• The system has a function called, egi(), that globally enables the interrupts.
• The interrupt service routine (ISR) definition is same as your AVR device, i.e. you can
implement a specific ISR function as:
ISR(ISR vector name){}
Assume that you are creating a PWM waveform with 25% duty cycle, which will be observed
on an LED with the following sequence:
Start LED OFF Compare A occurs LED ON Timer overflows Back to Start
The period of the PWM waveform should be the maximum value you can have for this given
timer unit (i.e. the maximum value you can time with this timer).
Use the following code skeleton to implement this PWM waveform using interrupts. Noninterrupt driven answers will not receive any credit.
i. You should implement the timer_init() function (sets up the timer
parameters).
ii. You can assume that there are predefined variables for registers (TCR, TCNT,
OCRA, OCRB, etc.).
iii. You should use the predefined statements (see the two #define statements) to
turn on and off the LED.
iv. You should use the two given ISR skeletons to implement the relevant
interrupts. These ISRs are where the duty cycle is created. Note that in the ISR
skeletons, the ISR vector names are not written; you need to fill in those parts.
v. The infinite loop in the main function should be empty.
COMPE375 Exam3 – 4
ISR(Timer_OVF_vect){
LEDOFF;
}
ISR(Timer_OCRA_vect){
LEDON;
}
void timer_init(){
/* Here you need to choose the normal mode with pre-scale 64 to get the
maximum possible period with this given timer (counting maximum number of
cycles with the highest pre-scale value). The PWM structure requires the
OFF time until OCRA compare match happens. Thus, the value of OCRA should
correspond to 75% OFF time. Then, since the MAX value for the normal mode
has 256 time units and the value of OCRA corresponds to 75% OFF time, the
OCRA value becomes 256*(1-0.25) – 1 = 191. */
OCRA = 191; //set the OCRA value
TCR &= ~(1<<2); //set the timer mode to normal mode
TCR |= (1<<3) | (1<<4); //enable the OCIE/OCIA interrupts
TCR |= (1<<0) | (1<<1); //set the pre-scaler value to 64
}
int main(){
egi();
timer_init();
while(1){
}
return 0;
}
COMPE375 Exam3 – 5
2 – Analog I/O Programming [30 pts]
Assume that we have the microcontroller system with ADC description given in file
“datasheet_for_q2”:
• The microcontroller is an 8-bit system.
• The ADC unit is a 5-bit Analog to Digital Converter.
• We have an 8-bit control and status register for the ADC unit called ADC_CSR, with
the following bit descriptions:
7th bit 6th bit 5th bit 4th bit 3rd bit 2nd bit 1st bit 0th bit
CH2 CH1 CH0 CC SC – – –
where:
o CH2-CH1-CH0 bits are used for channel selection, i.e. this ADC unit has 8
channels. (111 Channel 7, 110 Channel 6, … , 000 Channel 0)
o SC bit is used to start a conversion. When this bit is set to 1, an ADC conversion
operation starts. This bit is automatically cleared when the conversion ends.
o CC bit is used to inform the system that an ADC conversion has completed. This
bit is set to 1 when conversion ends and automatically cleared when the conversion
value is read.
o The other bits are reserved.
• The ADC conversion result is stored in an 8-bit register, named ADC_DR. This
assignment by default occurs in a right-justified way, i.e. the ADC conversion result is
by default placed in the 5 least significant bits of ADC_DR.
Write a function, using the prototype below, that has the following functionalities:
• The function should take two parameters: a pointer that represents the beginning point
of a character array (arr) and the size of the incoming array (size).
• Each array element, arr[i], should be filled with ADC conversion result from the ADC
channel “i modulo 8”. ADC channel should be set before a conversion starts. For
example, arr[0] is assigned to the conversion result from channel 0, arr[1] is assigned
to the conversion result from channel 1, etc.
• ADC conversions should be handled sequentially, starting with the conversion that
corresponds to the array element with index 0.
• For each conversion, you should wait until the ADC conversion ends to read the
conversion value.
• Each ADC conversion value should be left justified (the ADC result should be in the
5 most significant bits and the 3 least significant bits are zeros) before stored in the
corresponding array location.
COMPE375 Exam3 – 6
void myFunction(char* arr, int size){
int i;
char current_channel;
for(i=0; i<size; i++){
//First, set the ADC channel
current_channel = i & 7; // OR i % 8
ADC_CSR &= ~(0b11100000); //Clear the CH bits
ADC_CSR |= current_channel << 5; //Set the CH bits
/* Here, there are two important observations:
Sample Solution
Compelling correspondence is essential to the achievement all things considered but since of the changing idea of the present working environments, successful correspondence turns out to be more troublesome, and because of the numerous impediments that will permit beneficiaries to acknowledge the plan of the sender It is restricted. Misguided judgments.In spite of the fact that correspondence inside the association is rarely completely open, numerous straightforward arrangements can be executed to advance the effect of these hindrances.
Concerning specific contextual analysis, two significant correspondence standards, correspondence channel determination and commotion are self-evident. This course presents the standards of correspondence, the act of general correspondence, and different speculations to all the more likely comprehend the correspondence exchanges experienced in regular daily existence. The standards and practices that you learn in this course give the premise to additionally learning and correspondence.
This course starts with an outline of the correspondence cycle, the method of reasoning and hypothesis. In resulting modules of the course, we will look at explicit use of relational connections in close to home and expert life. These incorporate relational correspondence, bunch correspondence and dynamic, authoritative correspondence in the work environment or relational correspondence. Rule of Business Communication In request to make correspondence viable, it is important to follow a few rules and standards. Seven of them are fundamental and applicable, and these are clear, finished, brief, obliging, right, thought to be, concrete. These standards are frequently called 7C for business correspondence. The subtleties of these correspondence standards are examined underneath: Politeness Principle: When conveying, we should build up a cordial relationship with every individual who sends data to us.
To be inviting and polite is indistinguishable, and politeness requires an insightful and amicable activity against others. Axioms are notable that gracious “pay of graciousness is the main thing to win everything”. Correspondence staff ought to consistently remember this. The accompanying standards may assist with improving courtesy:Preliminary considering correspondence with family All glad families have the mystery of progress. This achievement originates from a strong establishment of closeness and closeness. Indeed, through private correspondence these cozy family connections become all the more intently. Correspondence is the foundation of different affiliations, building solid partners of obedient devotion, improving family way of life, and assisting with accomplishing satisfaction (Gosche, p. 1). In any case, so as to keep up an amicable relationship, a few families experienced tumultuous encounters. Correspondence in the family is an intricate and alluring marvel. Correspondence between families isn’t restricted to single messages between families or verbal correspondence.
It is a unique cycle that oversees force, closeness and limits, cohesiveness and flexibility of route frameworks, and makes pictures, topics, stories, ceremonies, rules, jobs, making implications, making a feeling of family life An intelligent cycle that makes a model. This model has passed ages. Notwithstanding the view as a family and family automatic framework, one of the greatest exploration establishments in between family correspondence centers around a family correspondence model. Family correspondence model (FCP) hypothesis clarifies why families impart in their own specific manner dependent on one another ‘s psychological direction. Early FCP research established in media research is keen on how families handle broad communications data. Family correspondence was perceived as an exceptional scholastic exploration field by the National Communications Association in 1989. Family correspondence researchers were at first impacted by family research, social brain science, and relational hypothesis, before long built up the hypothesis and began research in a family framework zeroed in on a significant job. Until 2001, the primary issue of the Family Communication Research Journal, Family Communication Magazine, was given. Family correspondence is more than the field of correspondence analysts in the family. Examination on family correspondence is normally done by individuals in brain science, humanism, and family research, to give some examples models. However, as the popular family correspondence researcher Leslie Baxter stated, it is the focal point of this intelligent semantic creation measure making the grant of family correspondence special. In the field of in-home correspondence, correspondence is normally not founded on autonomous messages from one sender to one beneficiary, yet dependent on the dynamic interdependency of data shared among families It is conceptualized. The focal point of this methodology is on the shared trait of semantic development inside family frameworks. As such, producing doesn’t happen in vacuum, however it happens in a wide scope of ages and social exchange.
Standards are rules end up being followed when performing work to agree to a given objective. Hierarchical achievement relies significantly upon compelling correspondence. So as to successfully impart, it is important to follow a few standards and rules. Coming up next are rules to guarantee powerful correspondence: clearness: lucidity of data is a significant guideline of correspondence. For beneficiaries to know the message plainly, the messages ought to be sorted out in a basic language. To guarantee that beneficiaries can without much of a stretch comprehend the importance of the message, the sender needs to impart unmistakably and unhesitatingly so the beneficiary can plainly and unquestionably comprehend the data.>