Community
cancel
Showing results for 
Search instead for 
Did you mean: 
MBeck5
Novice
1,259 Views

Switching pins between modes.

Found a version of Ubunto 16.04 LTS (http://people.canonical.com/~platform/snappy/tuchuck/desktop-beta4/tuchuck-xenial-desktop-iso-201701... http://people.canonical.com/~platform/snappy/tuchuck/desktop-beta4/tuchuck-xenial-desktop-iso-201701... . It works for me), offering access to everything on J12. Wrote a couple of short programs to allow going through and checking each bit for output and input.

Recently upgraded MRAA to 1.6.1. The only thing this library is missing, truly, is having all that web-based documentation turned into locally-usable man-pages. Please?

In some cases PWM0 is needed as an oscillator, and in others a GPIO. It seems disabling PWM0 leaves the output at 0V and I need it at near 3.3V.

I think I've tried just about every gyration possible to make this happen... and so I turn to this group for help.

I can set PWM0 as a GPIO. That works.

I can set PWM0 as an oscillator. That works. This is two separate programs.

But say PWM0 is programmed as an oscillator and now needs to be switched to GPIO.

mraa_enable(pwm, 0); // Disable output..

mraa_close(pwm); // release pin (?)

mraa_gpio_context gpio = mraa_gpio_init(26); // Always returns a non-NULL value.

mraa_gpio_dir(gpio, MRAA_GPIO_OUT); // Always succeeds.

mraa_gpio_write(gpio, 1); // Always succeeds.

That mraa_gpio_write() returns MRAA_SUCCESS... but my 'scope and voltmeter say otherwise.

What step am I missing?

Your time is appreciated.

Mark

Tags (1)
7 Replies
idata
Community Manager
77 Views

Hello Mark,

 

 

Thanks for reaching out!

 

 

The following is a simple script I wrote that successfully uses PWM and then GPIO functions on the same pin. I tested this successfully on a LED:

 

 

# include

 

 

# include "mraa.h"

 

 

int

 

main()

 

{

 

mraa_init();

 

//! [Interesting]

 

mraa_pwm_context pwm;

 

pwm = mraa_pwm_init(26);

 

if (pwm == NULL)

 

{

 

return 1;

 

}

 

mraa_pwm_period_us(pwm, 200);

 

mraa_pwm_enable(pwm, 1);

 

 

float value = 0.0f;

 

int count = 0;

 

 

while (count < 250)

 

{

 

count = count + 1;

 

value = value + 0.01f;

 

mraa_pwm_write(pwm, value);

 

usleep(50000);

 

if (value >= 1.0f)

 

{

 

value = 0.0f;

 

}

 

float output = mraa_pwm_read(pwm);

 

printf("PWM value is %f\n", output);

 

}

 

 

mraa_gpio_context gpio;

 

int ledstate = 0;

 

gpio = mraa_gpio_init(26);

 

mraa_gpio_dir(gpio, MRAA_GPIO_OUT);

 

count = 0;

 

 

while(count < 5)

 

{

 

count = count + 1;

 

ledstate = !ledstate;

 

mraa_gpio_write(gpio, ledstate);

 

sleep(1);

 

}

 

return 0;

 

}

 

 

I hope this simple code helps you,

 

Pedro M.
MBeck5
Novice
77 Views

Hello Pedro -

I take your code, compile with the following: gcc file.c -o file -lmraa

It compiles no problem, not one squeak out of the toolchain.

I run your code: sudo ./file

There is the PWM output followed by a toggling bit. Okay, that works.

Run it a second time.

I don't see any PWM output. Toggling, yes. PWM, no.

Except. I reboot the Joule. Then re-run the program.

There is the PWM output. Followed by toggling.

But there's no PWM output. when run a second time. There is toggling.

If your code runs multiple times and always produces PWM followed by toggling then I have a different problem. May I ask which OS you're running? And which version of MRAA?

Here, uname -a reports:

Linux Joule 4.4.0-1000-joule # 0+joule12-ubuntu SMP PREEMPT Fri Jan 6 04:28:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

mraa-gpio version reports

Version 1.6.1 on INTEL JOULE EXPANSION

Mark

idata
Community Manager
77 Views

I just tested this again on my Joule and I'm having the same behavior as you. PWM works only the first time, I'm not sure what might be happening. You see, I wrote that script a while ago, originally for a test on my Edison and I worked with no issues, PWM continued to work without any problems. So, I took that code, I slightly modified it to work on Joule and I only tested it once on Joule to make sure it worked before sharing it with you. So, I completely missed this issue.

 

 

Please let us investigate about this behavior and we'll get back to you once we have any useful update.

 

 

Pedro M.
MBeck5
Novice
77 Views

Hello Pedro -

Thank you. Am looking forward to some kind of resolution or workaround.

The alternative is connecting PWM0 to the input of a 2-input NAND gate with the other input connected to another GPIO. But I'm a little short of GPIOs... and would have to add more hardware elsewhere.

Your time is appreciated.

Mark

idata
Community Manager
77 Views

Hello Mark,

 

 

We completely understand your situation. I would like to point out that we are currently working on this. It is really helpful that you highlighted this behavior so we can work on preventing it. Right now, we have no updates but as soon as we know anything new, we'll make sure to share it with you.

 

 

Pedro M.
idata
Community Manager
77 Views

Hello Mark,

 

 

Thank you for your interest in Joule.

 

 

We would like to offer our sincere apologies for delaying a response to your issue. We have confirmed the issue you brought to our attention and are working diligently to resolve it. Unfortunately, we do not have an ETA for release.

 

 

Pedro M.
MBeck5
Novice
77 Views

Hello Pedro -

At the moment, a "temporary" work-around is in place: don't use a PWM output as a GPIO. It took some convincing of the HW engineer to design in... then I showed the group your note of April 24 and that settled the matter.

Regards,

Mark

Reply