Results 1 to 7 of 7

Thread: Axon hardware interrupts, help!

  1. Axon hardware interrupts, help!

    I have the following code:

    Code:
    volatile int32_t left_clicks = 0;
    volatile int32_t right_clicks = 0;
    const int WHEEL_UPDATE = 64;
    
    
    ISR (SIG_INTERRUPT4)
    	{
    	if(bit_is_clear(PINE,3))
    			{
    			left_clicks++;
    			}
    		else
    			{
    			left_clicks--;
    			}
    	}
    
    ISR (SIG_INTERRUPT5)
    	{
    	if(bit_is_clear(PINC,1))
    			{
    			right_clicks++;
    			}
    		else
    			{
    			right_clicks--;
    			}
    	}
    
    void main(void)
    	{
    	cbi(DDRC, PC1); //right dir, set for input
    	cbi(DDRE, PE5); //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=0b00110000; //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); //prints left and right click total every second
    			reset_timer0();
    			}	
    		}
    		
    	}

    This works perfectly for the left wheel but some odd behavior is generated for the right wheel. If the left wheel is rolled backwards so it goes negative then right_clicks is set to -1. If the left wheel is rolled back to positive clicks then right_clicks is set to 0. Rolling the right wheel has no effect.

    If I swap where the sensors are plugged in then the right wheel works (it changes left clicks). So its not a sensor hardware problem. Its the software or a problem with the Axon.

    Any help would really be appreciated, this is driving me crazy.

  2. Re: Axon hardware interrupts, help!

    Ok, I am unhappy now.

    Why does:
    Code:
    rprintf("Left:%d  Right:%d\n",left_clicks,right_clicks);
    not actually print out left_clicks and right_clicks? It only prints left_clicks and some other variable that is either 0 or -1 where right_clicks should go...

    I put in this code:
    Code:
                rprintf("Right:%d\n",right_clicks);
                rprintf("Left:%d\n",left_clicks);
    And everything works brilliantly.

  3. #3
    Join Date
    Apr 2008
    Location
    Sunnyvale, CA
    Posts
    378
    Images
    34
    Rep Power
    56

    Re: Axon hardware interrupts, help!

    Quote Originally Posted by Resilient View Post
    Why does:
    Code:
    rprintf("Left:%d  Right:%d\n",left_clicks,right_clicks);
    not actually print out left_clicks and right_clicks? It only prints left_clicks and some other variable that is either 0 or -1 where right_clicks should go...
    Might be the size of the data type. printf() has to infer the size of the data pushed on the stack from the format string, so if you use the wrong formats it'll look at the wrong part of the stack. You should check your docs and see if "%d" can handle an int32_t. You might need "%ld" instead.

  4. Re: Axon hardware interrupts, help!

    Quote Originally Posted by metaform3d View Post
    Might be the size of the data type. printf() has to infer the size of the data pushed on the stack from the format string, so if you use the wrong formats it'll look at the wrong part of the stack. You should check your docs and see if "%d" can handle an int32_t. You might need "%ld" instead.
    Thanks for the idea. I wish the AVR documentation was better, but there just inst much info on the rprintf function. I know %ld is not a possible option though. So it may just be a limitation of the function.

  5. Re: Axon hardware interrupts, help!

    I call this cross forum double posting

    http://www.societyofrobots.com/robot...56801#msg56801

  6. Re: Axon hardware interrupts, help!

    Quote Originally Posted by societyofrobots View Post
    I call this cross forum double posting

    http://www.societyofrobots.com/robot...56801#msg56801

    Damn I was caught!

  7. #7
    Join Date
    Apr 2008
    Location
    Sunnyvale, CA
    Posts
    378
    Images
    34
    Rep Power
    56

    Re: Axon hardware interrupts, help!

    Quote Originally Posted by Resilient View Post
    Thanks for the idea. I wish the AVR documentation was better, but there just inst much info on the rprintf function. I know %ld is not a possible option though. So it may just be a limitation of the function.
    You could try:
    Code:
    rprintf("Left:%d  Right:%d\n", (int)left_clicks, (int)right_clicks);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. News/Announcement Axon Microcontroller (product release)
    By societyofrobots in forum Robot Computers
    Replies: 58
    Last Post: 07-19-2010, 02:59 AM
  2. How can I fry my Axon?
    By Resilient in forum Arbotix, Microcontrollers, Arduino
    Replies: 3
    Last Post: 02-19-2009, 05:09 AM
  3. Question(s) question on axon microcontroller board
    By robot maker in forum Robot Computers
    Replies: 2
    Last Post: 08-31-2008, 12:40 PM
  4. A Software guy in a Hardware world...
    By Adman in forum Arbotix, Microcontrollers, Arduino
    Replies: 3
    Last Post: 03-14-2008, 03:13 PM
  5. Trossen Robotics System versus the competition?
    By Nammo in forum Software and Programming
    Replies: 10
    Last Post: 11-28-2007, 04:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •