Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
volatile uint32_t left_clicks = 0;volatile uint32_t right_clicks = 0;const int WHEEL_UPDATE = 64;ISR (SIG_INTERRUPT4) { if(left_dir) { left_clicks++; } else { left_clicks--; } }ISR (SIG_INTERRUPT6) { if(right_dir) { right_clicks++; } else { right_clicks--; } }void main(void) { cbi(DDRC, PC1); //right dir, set for input cbi(DDRE, PE6); //right clock, set for input cbi(DDRE, PE4); //left clock, set for input cbi(DDRE, PE3); //left dir, set for input EICRB = 0b00100010; //sets pind 4 and 6 to interrupt on falling edge EIMSK=0b01010000; //enables interrupts on 4 and 6 sei (); while(1) { current_time = get_timer0_overflow()/WHEEL_UPDATE; if(current_time >= 1) { rprintf("Left:%d Right:%d\n",left_clicks,right_clicks); reset_timer0(); } } }
rprintf("Left:%d%d Right:%d%d\n",left_clicks,right_clicks);
To be honest I never really understood rprintf entirely myself, and found a quirk in it for long ints. Try this:Code: [Select]rprintf("Left:%d%d Right:%d%d\n",left_clicks,right_clicks);Also, read through this post:http://www.societyofrobots.com/robotforum/index.php?topic=3006.0
rprintf("Left:%ul Right:%ul\n",left_clicks,right_clicks);
#ifndef RPRINTF_COMPLEX #define RPRINTF_COMPLEX#endif