Hi peoples!!!
I using a Timer for create a Odometer with a Encoder, but I need a big counter, like a uint32 or more, like a uint64, i need test on field for get the limit.
How I can grow the limit of Timer count, for get more.
And more, I need count 1 each 2000 clock from Encoder, someone could help me?
I use this code:
const uint8 enconder_prescaler = 2000;
void configEncoder(){
timer_init(TIMER2);
timer_cc_set_pol(TIMER2, 1, 1);
timer_cc_set_pol(TIMER2, 2, 1);
timer_get_reg_map(TIMER2)->CCMR1 |= TIMER_CCMR1_CC1S; //set both channels
timer_get_reg_map(TIMER2)->SMCR |= TIMER_SMCR_SMS_ENCODER1 | TIMER_SMCR_SMS_ENCODER2;
timer_set_prescaler(TIMER2, encoder_prescaler);
timer_resume(TIMER2);
}
char* readEncoder(){
newPosition = timer_get_count(TIMER2) >> 2;
// abs() avita que a direção tenha mudado
// e o valor esteja negativo devido a contagem invertida e atrasos
if(newPosition != oldPosition || isForceRead()){
direction = (newPosition > oldPosition && abs(newPosition-oldPosition) <30);
concat(bufE, bufESize, oldPosition, newPosition, direction);
oldPosition = newPosition;
}
else{
return "";
}
return bufE;
}
Based in this post: http://forums.leaflabs.com/topic.php?id=1566#post-10229
Thanks.