I want to drive a servo using maple.
Would an import of the servo library from arduino IDE into maple's IDE work.
Also I understand that maple works at 3.3V and servo requires 5V input so would a 3.3 to 5 V level shifter work.
Driving servo using maple
(19 posts) (7 voices)-
Posted 5 years ago #
-
Anitmatter,
The servo library for Arduino uses interrupts to drive multiple servos from each hardware timer. This also allows servos to be driven on pins that don't have timer capability. The Arduino servo library will need to be converted to be used on the Maple due to differences in the hardware timers. Has anyone converted the servo library yet?
http://leaflabs.com/docs/maple/compatibility/
http://leaflabs.com/docs/maple/timers/
http://leaflabs.com/docs/maple/pwm/Note that if you just need a single servo, it would be much simpler to connect the servo to a pin that has a timer attached and use the PWM functions.
Also, many servos seem to work fine with a 3.3V digital output. You could also use 5V level shifter hardware as suggested, or use a 5V tolerant pin in OUTPUT_OPEN_DRAIN mode with a pullup resistor to +5V
CarlO.
Posted 5 years ago # -
Clarification: the PWM output mode does not support open-drain outputs, so using the timer to directly drive the servo would not allow for 5V output using pullup resistor.
CarlO
Posted 5 years ago # -
CarlO is correct!
The PWM output not supporting open-drain is kind of frustrating, there may be a way around this using a different timer output-compare mode but I haven't found it yet. Using HardwareTimer with an digitalWrite() interrupt handler in open-drain mode would definately work:
http://leaflabs.com/docs/maple/gpio/Depending on the size and model of the servo you are using, you may also be able to get by with +5v on the "power" wire, GND on ground, and 3.3v PWM output on the signal line. I've done this to play with cheap hobby servos using USB +5v from the Vin pin for power, but this puts a lot of load on the USB port. The Servo library is not ported yet, but the PWM page in the documentation describes how to get one working, and there's a servo sweep mode in the interactive test session to test exactly this behavior.
Posted 5 years ago # -
HDF - I missed that!
Can anyone tell me which document says that timer PWM output pins can't operate in open-drain? Is it in the GPIO section, or in the timers?
In RM0008 (13902.pdf), or somewhere else?I am nervous that I may have missed some other pin restrictions now :-(
I am using a buffer (74HCT04) for level translation for motor drive, but I was assuming I could do PPM for servo's directly from a timer, just using pull-ups.
Back to the (Eagle) drawing board :-(Posted 5 years ago # -
I too am uncertain of the validity of this. We fooled around a bit to get OD PWM working and failed, but didnt try THAT hard, nor did we find an official reference to its impossibility.
incidentally, cant an open drain pin be created with a an npn fet, with "output" at the drain (top) but otherwise floating, and the ground the source and connect the PP output from the pin to the base....
Posted 5 years ago # -
I was just going by what the Maple PWM docs state.
from http://leaflabs.com/docs/maple/pwm/
pinMode(pin_num, PWM)
This command is usually called from setup() to tell the microcontroller that pin_num should be configured to PWM output. PWM implies regular driven OUTPUT (not open drain etc).Apparently the Maple library currently only supports Push-Pull when the pin is set up for PWM output, but the STM32 may support other modes. Is that correct?
CarlO.
Posted 5 years ago # -
Okay. I should have some time towards the end of this month to do some experiments, and it is important enough that I may try before then.
Reading the GPIO section, there is an awful lot of stuff to get right, and in the right order. It may be that it does work, but mortals (i.e. everyone that didn't design the chip) can't figure out how.
I think I'll go to the ST forums and ask.
CarlO and poslathian, thanks for the "heads-up", it is important to me to bottom this out.
(exits muttering "... 20+ servo robot, ... pull-ups, ... rule world ... :-)Posted 5 years ago # -
What I tried was removing anything that looked like it was setting the pin mode from pwm.c and then called setPinMode(OUTPUT_OPEN_DRAIN) before or after calling pwmWrite() and testing for a waveform with a pull up connected. I also looked in the reference manual and found no mention (possible or not possible) on alternative pin modes in the PWM configuration section. It may very well be possible but I don't know how to do it so I edited the docs conservatively.
Posted 5 years ago # -
bnewbold - much better conservative and correct than misleading !-)
I find the GPIO part of RM0008 a bit of a slog to read, but I vaguely remember it talking about two 'default' and alternative output drive structures. I'll try to look this weekend, but maybe the open drain interacts with something in the alternative pin drive configuration?
Posted 5 years ago # -
I finally got round to asking about Open Drain outputs on PWM.
One answer was posted by Clive1:
( https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fARM%20CortexM3%20STM32%2fCan%20TIM3%20PWM%20outputs%20be%20set%20to%20Open%20Drain&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E&TopicsView=https%3A%2F%2Fmy%2Est%2Ecom%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FARM%20CortexM3%20STM32%2FAllItems%2Easpx¤tviews=41 )"Wouldn't you just program the GPIO pins into the Alternate Function, Open Drain mode? instead of the normal Push-Pull (GPIO_Mode_AF_PP)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);Presumably you've checked the pins are in the 5V tolerant group?"
Posted 5 years ago # -
Hi guys,
There is an alternate function open drain mode--it's in the library but I accidentally left it out as an option in the wirish interface. I don't have a maple with me to test it at the moment but if somebody can apply the following patch and test it, I'll commit it into libmaple.
perry@mescaline ~/work/libmaple $ (master) git diff diff --git a/wirish/io.h b/wirish/io.h index e779604..4aa1eef 100644 --- a/wirish/io.h +++ b/wirish/io.h @@ -47,7 +47,8 @@ typedef enum WiringPinMode { INPUT_PULLUP, INPUT_PULLDOWN, INPUT_FLOATING, - PWM + PWM, + PWM_OPEN_DRAIN, } WiringPinMode; diff --git a/wirish/wirish_digital.c b/wirish/wirish_digital.c index c93c786..9dd46ed 100644 --- a/wirish/wirish_digital.c +++ b/wirish/wirish_digital.c @@ -58,6 +58,9 @@ void pinMode(uint8 pin, WiringPinMode mode) { case PWM: outputMode = GPIO_MODE_AF_OUTPUT_PP; break; + case PWM_OPEN_DRAIN: + outputMode = GPIO_MODE_AF_OUTPUT_OD; + break; default: ASSERT(0); return;
Posted 5 years ago # -
iPerry, I will have to try this. From digging in to the docs more closely, it would appear that AF OpenDrain is unique to I2C, the timers offer no such feature. Which is annoying, considering the circuit that drives the pin either PP or OD is downstream from the alternate function input.
This may be a docs bug, will try your code.
Posted 5 years ago # -
Please post if you get some clarity on this. I am going to start pocking at it too later in the week, and I'd hate to just reproduce your results, but a week later :-)
Clive1 and I exchanged another round of posts over at ST.com. He hadn't tried exactly the permutation of behaviour, but seemed pretty comfortable that their is a good chance it should work.
Posted 5 years ago # -
This is the code I wrote when testing the Maple with a servo:
http://www.crennsmind.com/Code/Maple/Servo/Servo_Control.txt
I used a 5V tolerant pin just in case I got feedback from the servo (even though it's highly unlikely, if at all possible) but I don't think that's an issue. The servo didn't make a fuss about the 3.3v signal (used Vin from the Maple to power the Servo since it had no load on the servo) and seemed to work well. The upper and lower limits were calculated with the known period and range of the timer's counter. I'll attempt to port the servo library over in the next few days (after I get back from my trip) but the above code should get you started.
Posted 5 years ago #
Reply »
You must log in to post.