Discussion point : Question 9 (What is output frequency of the signal generated from given code?)

Discussion point : Question 9 (What is output frequency of the signal generated from given code?)




Response:

Clock to timer = 30 MHz (pclk value)
Prescalar value  = 30 (loaded to T0PR)
So, the final clock to Timer/Counter = 30/30 = 1 MHz
Based on this time for each tick = 1/1 MHz = 1 uS

Loaded counter value = 100000 (loaded in T0MR1)

Time for each transition (Timer interrupt) of the signal = 100000 * 1 uS = 0.1

That means for one half of the signal, the time is 0.1
For combined positive and negative,  i.e., total time period of the signal generated = 0.2

Hence, frequency of generated signal is 1/0.2 = 5Hz

To generate 5KHz, load the Counter register T0MR1 with a value of 100 instead of 100000.

Post a Comment

0 Comments