Hey all, I was hoping for some tips.

 

I'm trying to get 4 channels (ail/ele/thr/rud) of input and output working on my ArduPilot Board.

 

I'm starting with the recent 2.6 version of the code.

 

I've managed to get all 4 channels inputting correctly to the board (Verified by adding adding ch4 to the print_radio() function.)

 

Now I'm working on getting PPM coming out for all 4 channels.

 

Any tips on the best way to add the fourth channel of output to the Ardupilot?

Which pin is best suited to be used for the fourth PPM out?

 

I don't mind sniffing through manuals or existing code, but I've been hacking around the datasheets for a couple hours this evening and am still scratching my head.

 

Cheers,

 

Tom

 

Views: 412

Reply to This

Replies to This Discussion

Hi Tom,

We haven't really pursued 4 channels on the current board because of the limited timer resources. If you look at the interrupt vectors in the servos.pde file and see the difference in the way that ch3 is formed versus ch1 and ch2 you will understand. The resolution avaialble for ch3 (and ch4) is poor. With ch3 going to an esc it is not so bad, but for driving an actual servo the output will be very coarse and prone to jitter.
There is a sixteen bit timer running ch 1 and 2. I thinks it's running fast pwm. Basically it counts up to 40000 and loops There are two compare values that are triggered with an interrupt. I already use the timers to hijack the radio input code using pin interrupts and the timer as offset values. I feel like this was a stretch but it works great. I can't see a way to trick the timer into doing a tire task, but I'm always surprised how much functionality you can squeeze out of these systems.
That not a hack or hijack That's what the stuff was put there. That's how it should be done.
I figured out how your radio read works. I added a channel using your template. Figuring out how
the code works is how I learned C.
Hey Doug,

Whether or not it works well I think I'd still like to give it a go... see with my own eyes how jittery it is. It also can't hurt to learn how this stuff works.


All:
I also got the fourth channel of input working fairly easily by adding an if(PINB & B00010000) case.

While figuring out how the servo write is working, I found this website that explained it better than any other I found:

http://mil.ufl.edu/~achamber/servoPWMfaq.html

One thing I haven't really been able to find is a decent description of what the different available interrupt vectors are. For instance, TIMER1_CAPT_vect, TIMER2_COMPA_vect, etc. Don't seem to be in the ATMEL data sheet, and finding reference to them on Arduino Playground is hit or miss. Where could I go to find their definitions and see what else might be available?

Cheers,

Tom
I think you will find them all in the ATMEL data sheet, although not with the Arduino names.
I think I've found it.

From iom328p.h which is in the Arduino IDE.

/* Interrupt Vectors */
/* Interrupt Vector 0 is the reset vector. */
#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
#define WDT_vect _VECTOR(6) /* Watchdog Time-out Interrupt */
#define TIMER2_COMPA_vect _VECTOR(7) /* Timer/Counter2 Compare Match A */
#define TIMER2_COMPB_vect _VECTOR(8) /* Timer/Counter2 Compare Match A */
#define TIMER2_OVF_vect _VECTOR(9) /* Timer/Counter2 Overflow */
#define TIMER1_CAPT_vect _VECTOR(10) /* Timer/Counter1 Capture Event */
#define TIMER1_COMPA_vect _VECTOR(11) /* Timer/Counter1 Compare Match A */
#define TIMER1_COMPB_vect _VECTOR(12) /* Timer/Counter1 Compare Match B */
#define TIMER1_OVF_vect _VECTOR(13) /* Timer/Counter1 Overflow */
#define TIMER0_COMPA_vect _VECTOR(14) /* TimerCounter0 Compare Match A */
#define TIMER0_COMPB_vect _VECTOR(15) /* TimerCounter0 Compare Match B */
#define TIMER0_OVF_vect _VECTOR(16) /* Timer/Couner0 Overflow */
#define SPI_STC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
#define USART_RX_vect _VECTOR(18) /* USART Rx Complete */
#define USART_UDRE_vect _VECTOR(19) /* USART, Data Register Empty */
#define USART_TX_vect _VECTOR(20) /* USART Tx Complete */
#define ADC_vect _VECTOR(21) /* ADC Conversion Complete */
#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
#define TWI_vect _VECTOR(24) /* Two-wire Serial Interface */
#define SPM_READY_vect _VECTOR(25) /* Store Program Memory Read */

#define _VECTORS_SIZE (26 * 4)

As well as the attached PDF excerpt.
Attachments:
Arduino defines for ATMega328 interrupt vectors - from the file:
~\arduino-0017\hardware\tools\avr\avr\include\avr\iom328p.h

#define INT0_vect _VECTOR(1) /* External Interrupt Request 0 */
#define INT1_vect _VECTOR(2) /* External Interrupt Request 1 */
#define PCINT0_vect _VECTOR(3) /* Pin Change Interrupt Request 0 */
#define PCINT1_vect _VECTOR(4) /* Pin Change Interrupt Request 0 */
#define PCINT2_vect _VECTOR(5) /* Pin Change Interrupt Request 1 */
#define WDT_vect _VECTOR(6) /* Watchdog Time-out Interrupt */
#define TIMER2_COMPA_vect _VECTOR(7) /* Timer/Counter2 Compare Match A */
#define TIMER2_COMPB_vect _VECTOR(8) /* Timer/Counter2 Compare Match A */
#define TIMER2_OVF_vect _VECTOR(9) /* Timer/Counter2 Overflow */
#define TIMER1_CAPT_vect _VECTOR(10) /* Timer/Counter1 Capture Event */
#define TIMER1_COMPA_vect _VECTOR(11) /* Timer/Counter1 Compare Match A */
#define TIMER1_COMPB_vect _VECTOR(12) /* Timer/Counter1 Compare Match B */
#define TIMER1_OVF_vect _VECTOR(13) /* Timer/Counter1 Overflow */
#define TIMER0_COMPA_vect _VECTOR(14) /* TimerCounter0 Compare Match A */
#define TIMER0_COMPB_vect _VECTOR(15) /* TimerCounter0 Compare Match B */
#define TIMER0_OVF_vect _VECTOR(16) /* Timer/Couner0 Overflow */
#define SPI_STC_vect _VECTOR(17) /* SPI Serial Transfer Complete */
#define USART_RX_vect _VECTOR(18) /* USART Rx Complete */
#define USART_UDRE_vect _VECTOR(19) /* USART, Data Register Empty */
#define USART_TX_vect _VECTOR(20) /* USART Tx Complete */
#define ADC_vect _VECTOR(21) /* ADC Conversion Complete */
#define EE_READY_vect _VECTOR(22) /* EEPROM Ready */
#define ANALOG_COMP_vect _VECTOR(23) /* Analog Comparator */
#define TWI_vect _VECTOR(24) /* Two-wire Serial Interface */
#define SPM_READY_vect _VECTOR(25) /* Store Program Memory Read */

As Doug says these will be in the '328 data sheet but have different names there...HTH
Hey thanks Hopslink... I coulda sworn that your reply wasn't there when I replied below. :)

Tom
Is everyone from 2.5.1 here now ?
Earl
Ha, I consider everything I do a hack!
It's not obvious that the Timer2 is basically a clock that keeps perfect time and you can reference the clock even though the clock is being used for output and not input.
Yes, I learned C from reading other's code too.
I think you are looking at Arduino's abstraction of the timers. That won't do you any good if you want to push the limits...

Reply to Discussion

RSS

Groups

Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service