Hi, 

I am trying to customize the analog pin in a way such that the pin outputs analog signals between 0-5V to an amplifier with respect to RC inputs. Is this possible? 

Views: 2477

Reply to This

Replies to This Discussion

I think that normally the way that's done is the micro controller outputs a pwm signal (i.e. a fast signal that flicks between 0 and 5v) and then you can put a cap on it that essentially averages the voltage.  In this way when the microcontroller can adjust the voltage by changing the amount of time it spends at 5V vs 0V.

That's my guess as to how it could be done but I'm not sure exactly about how that could be done in the code.  The regular analog pins on the left side of the board are probably too slow for that.  The pins on the back are all PWM outputs set-up for servos or ESCs.  I suspect it can be done but I think it would require some fairly low-level changes in the code.

Thanks for the reply, Randy. I wasn't aware that the analog pins might be too slow for the PWM signals, this explains a lot about the fact that I was able to read analog signals but was unable to output any through the analog pins. 

I had also tried to output constant voltage through the PWM outputs in an attempt to check if I was able to convert PWM signals to analog but failed to get the desired result. That might be due to the fact that I am using the ArduPilot Target 2 Simulink library and am fairly new to it. I will look more into using the PWM outputs instead. 

I am working on a project of a quadcopter/airplane hybrid. We have the APM 2.6, and we have 4 motors that can be tilted individually by a servo each. So, thats 4 motors and 4 servos that are being controlled by the 8 PWM output pins. Since i have run out of the conventional output pins, i am trying to use one of the analog pins as a digital output pin to control a 5th servo that would go to a rudder. Supposedly you are supposed to be able to do this from here (scroll to bottom), by adding 54 to number of the analog pin. 

But I am having trouble how to figure out how to initialize the pin to make it a digital output pin and then write a PWM value to it. Below is some code that I think should be able to make it work, but all i have been able to do is output 5V or 0V (make it a relay?). Could someone provide an example code of how to write PWM value to a digital output pin that corresponds to the A0-A12 analog pins on the APM 2.6?

const AP_HAL::HAL& hal = AP_HAL_AVR_APM2; // Hardware abstraction layer
void setup() 

{
hal.rcout->enable_ch(60);

}

void loop()
{

hal.gpio->analogPinToDigitalPin(60);

hal.rcout->write(60, 1500);

hal.gpio->write(60,1500);

}

AP_HAL_MAIN();

Eric,

     On the APM2.6 it actually has 10 pwm outputs already. what are labelled as A10 and A11 are pwm outputs that we normally use for the camera gimbal.  The AP_Mount code should show you how to output to those or if you've basing your code on arducopter the motors libraries will show how to output using the hal layer.

    By the way, the labelling on the side of the APM2.x is a bit confusing, the last two rows on that row of A0 ~ A11 are SPI pins.  "SPI" only appears once on the side but actually it should appear twice (because two rows of pins are used for SPI..i.e. 6 pins).

    A10 and A11 are not really analog pins at all.  They probably should have been labelled as RC10, RC11 or OUT10, OUT11.  Ah well.

Thanks for help, 

How do i tell the APM to write to A10 or A11 pins? I am using the libraries for ardupilot, but have been writing all the code myself, and not using the standard Ardrucopter/Arduplane firmware. I'm not too familiar with the coding side of things, and have fumbled a lot of the way to get where I am now. As of now, I have been using the command.

hal.rcout->write(PIN, PWM) to get the proper PWM signal on the output pins. I have tried using the convention of adding 54, so then hal.rcout(64, 1500) should be to A10 pin, but have failed so far to get any output. 

Since, I'm not too familiar with coding and C++, I dont know if pointing me to a .h or .cpp file will be enough for me, I may need a little more explicit of a step by step solution. 

Thanks!

Eric,

     I thought that the hal.rcout->write() command would directly take the number "10" to mean pwm output 10.  I don't think you need to worry about the physical pin number when you use that call because the hal layer does the mapping for you.

Thank you for the help, I got it to work, though if you want to write to A10, since the index for the digital pins starts at 0, the command is 


hal.rcout->write(9, pwm)

and then I needed to enable the channel beforehand in the setup() with

hal.rcout->enable(9)

Thanks for the help again, i've spent many many hours trying to figure out just this one problem. 

hey,

can i use the 4 port relay board (http://www.ebay.in/itm/331997386214?aff_source=Sok-Goog) to control led's directly from a APM 2.6??

Hey, you can use this reference which i got from Google. https://reviewsdash.net/best-fishing-drones/

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

© 2018   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service