What is Prescalar and Postscalar

Prescalar and Postscalar:


  • Prescalar divides the input pulse before the counter and Postscalar divides the output of the counter. 
  • Both effectively increase the range of the counter. 
  • Both prescalar and postscalar used to get our desired frequency from basic reference. 
  • The prescalar divides the reference frequency by some specific factor (which is entered into clock register/PLL register) and thus helps in reducing frequency, Postscalar does the opposite function. 
Cheers!!!!
-> Let us Embed <-

Quadrature encoder in C || Quadrature encoder by Software

Let us See how can we achieve a quadrature encoder in c (by software) in this tutorial

What is a Quadrature encoder?

It is a encoder with two channels where any change(raise or fall) in one channel (Say Channel A) will result change (raise or fall) in the other channel (Say Channel A) with 90deg phase shift.

This picture will help you to understand the quadrature encoder better


Here for a clock wise rotation of the encoder Channel A is leading Channel B and vise-versa for the anti clock wise rotation. As explained you can see the phase differences of 90deg between two channels by probing two channels.

Main advantage of quadrature encoder is capturing both the edges (rising and falling) for two channels (Channel A and Channel B) as a interrupt will result more number of pulses from the encoder.

How to find the direction with software?

You can find the direction using the below table

Interrupt From Channel
Status of Channel A
Status of Channel B
Direction

Channel A
High
Low
Clock wise rotation
Channel A
Low
High
Clock wise rotation
Channel B
High
High
Clock wise rotation
Channel B
Low
Low
Clock wise rotation
Channel A
High
High
Anti-Clock wise rotation
Channel A
Low
Low
Anti-Clock wise rotation
Channel B
High
Low
Anti-Clock wise rotation
Channel B
Low
High
Anti-Clock wise rotation

Program implementation:

Configure both Channel A and Channel B interrupts
Inside_Channel_A_ISR
{
       Clear_the_interrupt_if_needed;
       if(Stats_of_Channel_A != Status_of_Channel_B)
       {
              increment_Clock_wise_counter ++;
       }
       else
       {
             increment_counter_Clock_wise_counter ++;
       }
}
Inside_Channel_B_ISR
{
       Clear_the_interrupt_if_needed;
       if(Stats_of_Channel_B == Status_of_Channel_A)
       {
              increment_Clock_wise_counter ++;
       }
       else
       {
             increment_counter_Clock_wise_counter ++;
       }
}

If you can able to find the type of interrupt like raising or falling it will be easy for configuration.


Cheers!!!!
-> Let us Embed <-