Author Topic: Urgent help needed in connecting Radio Rx with Axon1 using external interrupts  (Read 2604 times)

0 Members and 1 Guest are viewing this topic.

Offline salirazaTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Hello All,

I have been working with Axon1 for past 3 years and now trying to use external interrupts for the first time in my life.

Admin, and anyone please help!!!

I want to read atleast one channel (throttle) in my Axon1 using external interrupts. I would be extremely grateful if you can provide a working code for this task.

I already have a code (function that i call) with which I am able to read the throttle using a digital input (PinA1) and timer2... the function is:

void radio(void){
   while(bit_is_set(PINA, 1)){}
   reset_timer2();
   while(bit_is_clear(PINA, 1)){}
   THR=(get_timer2_overflow()*256+TCNT2);
   THR=THR-134;//throttle range 0-108 with increments of 5
}

Using this my control loop rate suffers a lot! I would really like to use an external interrupt (either J6, or E5, E6, E7) to do this task for me. As I requested above please please provide a code that will work with Axon1 and its old library (Axon_Source_102009)

Regards,

Raza.

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Can you not use the input capture facility of one of the timers? That's interrupt time, so your main loop wouldn't be involved, except to process the results.

You don't say how often this needs to be done, but if it's only once in a while your main loop can enable the interrupt, and the ISR can disable it when done.

I'm not going to write code for you, someone else here might but I'd be surprised if so. It's detailed in the data sheet for the processor, and should be pretty straightforward.

Joe

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
I never actually wrote easy to use external interrupt support into my really old Axon code. You'll have to read through this and make sense of it:
http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html


Anyway, I strongly encourage you to move to WebbotLib. It's much easier to use and has way more features.


Another option would be to convert the RC digital signal to an analog one, which you can read quickly by ADC:
http://www.societyofrobots.com/remote_control_robot.shtml#components

Scroll down until you see this schematic below, and read the instructions above it:


Offline salirazaTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Hello and thank you joe61 and admin for your quick replies.

Joe61 you are right, pwm capture should do that. I already am using pwm generation using builtin hardware using timer3 and 4. I will try to do input capture.... but first need to read a bit about it... My apologies for simply asking without giving info about my system. I am doing flight control of a quadrotor, and for that process gyro, accel, mag, data, apply pid control for attitude stabilization and thus change 4 motor speeds (pwm values). Adding to that is my own RX input mostly for the collective throttle..... My control loop currently runs at 71Hz, and I want to increase this number.

Admin, I am already looking at webbot lib and envy its offerings .... I would really love to convert to webbot lib, however, this is a task that will require some time. I am on a very short deadline for now. Also, thanks for the analog input suggestion. I was using this same circuit initially and moved on to timers expecting a much linear and broad range. Later, learned that using interrupt would be the fastest..... My backup plan for now would be to use analog. I was hoping if I could get step by step instruction of how to setup J6, E5, 6 or 7 as input external interrupt and using timer2 or 5 to measure the pulse width.

When I try to do such it results in no response from Axon .... Here is what I did:

1. setup J6 as input in SoR_Utils
2. defining interrupt vector
3. not sure but some kind of masking is needed for PCINT ... for INT may be not?
4. setup to start timer on interrupt and then get timer value...

it does not work! :( I might be able to post the code lines I wrote for this task tomorrow.

Regards,

Raza.


Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
1. setup J6 as input in SoR_Utils
2. defining interrupt vector
3. not sure but some kind of masking is needed for PCINT ... for INT may be not?
4. setup to start timer on interrupt and then get timer value...

it does not work! :( I might be able to post the code lines I wrote for this task tomorrow.

Just to be sure I got what you meant, in general you need to write the interrupt handler, then you need to enable the individual interrupt using the appropriate register for the peripheral. Then you need to enable interrupts globally.

If you're using some form of avr-gcc (and I believe winAVR?) use sei() to enable interrupts globally. But only do that after you've setup all the peripheral interrupts you're going to use.

Maybe that's what you're already doing. I've got a cold though so my heads not up to speed this morning.

Posting code would be good, less guessing that way :-)

Joe


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Admin, I am already looking at webbot lib and envy its offerings ....
Converting is actually quite fast. It only took an hour or so to convert my entire ERP code to use WebbotLib.