Question

In: Electrical Engineering

11. Using Timer1 and CTC mode of the ATMega32, write an AVR C program that uses...

11. Using Timer1 and CTC mode of the ATMega32, write an AVR C program that uses the
hardware waveform generator to generate a square wave on pin OC1A with a
frequency of 50 Hz if PA1 is high, otherwise generate 60Hz. Assume XTAL = 8 MHz.
[10 Marks]

Solutions

Expert Solution

The frequency of the wave is given as

where f_clk_I/O is input clock frequency(clock frequency)

N is the Prescaler

OCRnA is the value in OCRA which is a 16-bit number value from 0 to 65535

So, to produce a wave with 60Hz,

We should have Prescaler to 8 and OCR1A to 8,320

To produce a wave with 50Hz

We should have Prescaler to 8 and OCR1A to 9,999

AVR C Code:

int main(void)
{
   DDRA |= 1<<DDA1;       //Sets PA1 as Output
   TCCR1A |= 1<<COM1A1;   //Clears OC1A on compare match
   TCCR1B |= 1<<WGM12;       //Setting to CTC Mode
   while(1)
   {
       if(PORTA &= 1<<PA1)
       {   //Setting to 50Hz if PA1 is High
           TCCR1B |= 1<<CS11;   //Setting Prescaler to 8
           OCR1A = 9999
       }
       else
       {   //Setting to 60Hz if PA1 is Low
           TCCR1B |= 1<<CS11;   //Setting Prescaler to 8
           OCR1A = 8320;
       }
   }
}


Related Solutions

Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Question 1: Answer the following questions related to AVR Timer/counter: Write an AVR program that flashes...
Question 1: Answer the following questions related to AVR Timer/counter: Write an AVR program that flashes an LED (PC0) every 6 ms using CPU clock frequency of 32 kHz and TIMER0. Use Timer/Counter0 Overflow Flag (TOV0) in your code. Write an AVR program that flashes an LED (PC0) every 2 seconds using XTAL clock frequency of 16MHz and Timer1. Use Timer/Counter1 Overflow Flag (TOV1) in your code.
Write a C program that opens a file called "numbers.txt" in writing mode. The program should...
Write a C program that opens a file called "numbers.txt" in writing mode. The program should then read floating point numbers from the keyboard, and write these lines to the opened file one per line, stopping when the number 0 is entered. Your program should check to make sure that the file was opened successfully, and terminate if it was not.
Timer 0 in normal mode (AVR) MSYS LAB8 I'm lost on how to write this.. #include...
Timer 0 in normal mode (AVR) MSYS LAB8 I'm lost on how to write this.. #include <avr/io.h> #include "led.h" // Prototype void T0Delay(); int main() {    unsigned char x = 0;    //Ready the LED-port    initLEDport();        DDRA = 0x00; //port A as input        DDRB = 0xFF; //port B as output    while(1)    {        // Wait 1/125 seconds        T0Delay();        // Increment and show the variable x       ...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Write a C program that has a local and a global variable. The program uses a...
Write a C program that has a local and a global variable. The program uses a fork to create a child process. The parent process modifies both variables to be 10 and 20 and prints out the values. Then the child process modifies both variables to be 100 and 200 and prints out the values? Explain the program output?
Write a C++ program that uses all the relational operators.
Write a C++ program that uses all the relational operators.
Write a C or C++ program that uses pthreads to compute the number of values that...
Write a C or C++ program that uses pthreads to compute the number of values that are evenly divisible by 97 between a specified range of values (INCLUSIVE). The program should accept 3 command-line arguments: low value high value number of threads to create to perform the computation -Specifics for program order of input: 0 9000000000 2 this means 0 to 9 Billion (INCLUSIVE); 2 threads alarm(90); this should be the first executable line of the program to make sure...
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT