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...
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.
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 uses all the relational operators.
Write a C++ program that uses all the relational operators.
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...
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers....
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using an ascending order selection sort, modified to print out the...
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT