1/3/2023 0 Comments Codevision timer![]() Setting this bit to ‘1’ enables the timer 1 overflow interrupt. ![]() The 3 rd bit of the TIMSK Register controls the timer 1 overflow interrupt. The same register is used to control the interrupt of timer 1. PORTD=0x00 // LED is connected in this port If you want to know about the basic of prescaler and how to initialize it, do check out this article. Do note that, I have taken 64 as a prescaler. Now we know how to set the timer interrupt of timer 0, we are ready to program. Setting this bit to ‘1’ enables the overflow interrupt of timer 0. The bit 0 of TIMSK Register controls the overflow interrupt of Timer 0. TIMSK or Timer/Counter Interrupt Mask Register is a control register used to mask or unmask the timer interrupts. Now we just need to know how to initialize the timer interrupt. Therefore, the microcontroller has to overflow 244 times for the delay generation of 1sec. On dividing, the value is 244.14 which is approximately equal to 244. ![]() But, if we divide the value to the delay required, we can know how many time the timer have to overflow to generate the delay of 1sec. Now, we know how much time the controller takes to count the value till 8 bit. Therefore, the time period of the controller should be 16 microseconds. Now, because the timer here I am using is 8 bit, therefore to find out the total time it takes to count till 8 bit multiplies the time period with 256(0-255 total 256 counts) which is 4096 microsecond. As we know, the frequency is an inverse of the Time period (T=1/F). This results the frequency of the controller is 64.5 KHz. As I have already stated above, the prescaler I am choosing is 64. ![]() After that, I am calculating the number of times it should overflow to generate the delay of 1sec. See, we know that the delay is very large so, I am choosing 8 as a prescaler. We need a bit of calculation before writing the code. I have connected the LED in PIN0 of Port D. The operating frequency of the microcontroller is 4 MHz. Suppose we have to generate a blink the LED in 1 sec interval. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |