chipKIT® Development Platform

Inspired by Arduino™

analogWrite on fubarino mini

Created Mon, 14 Apr 2014 17:49:52 +0000 by chaco


chaco

Mon, 14 Apr 2014 17:49:52 +0000

I'm trying to get analogWrite to work on a fubarino mini. I've read the info on PPS, and checked the possible pin mappings. I also notice on the fubarino mini website this text:

"PWM Pins Still Verifying, need to confirm the default pins are 4,7,8,9,10"

I haven't been successful getting it to work. For example, I've used the following:

mapPps(10, PPS_OUT_OC1);

I've also tried other pins, all with the same result: no PWM output, just a high or low output.

I did read this post "Post subject: PPS and OCx / analogWrite", but it ended inconclusively (is the only solution to create a new board definition file?)

I'd appreciate any ideas, suggestions.... Thanks.


EmbeddedMan

Tue, 15 Apr 2014 00:57:18 +0000

chaco,

I'll have to look into that. They should all work, but I haven't tested them in awhile.

However, in the meantime, I strongly suggest you use the SoftPWMServo library I wrote instead. It allows you to do the same thing ("analog" output by doing slow PWM output) but in software rather than hardware, which means you can do it on ANY pin, or ALL pins, at the same time. Not just 5! It's super cool, and works pretty well.

It's included with all MPIDE installs in the /hardware/pic32/libraries/SoftPWMServo folder.

*Brian


chaco

Tue, 15 Apr 2014 02:43:16 +0000

Hi Brian, Thanks for the suggestion to use your software PWM library. I'm concerned about timing though, as this will be used in conjunction with a sensor acquisition system for musical performance that uses all analog inputs (and the remaining digital inputs), and I want to avoid jitter and/or latency in the sensor acquisition timing. Can your library handle multiple PWM outputs without affecting the overall loop timing too much?

Thanks -- chaco


EmbeddedMan

Tue, 15 Apr 2014 03:09:18 +0000

chaco,

OK, I've verified the bug in the current MPIDE release. I've fixed the problem, and have confirmed all 5 PWMs on the Fubarino Mini are now working. I've issued a pull request and the fix will be in the next MPIDE test build.

In the meantime, I can send you the files you need to change if you want to fix it for yourself on your system before the next MPIDE test build. Just let me know.

Also, I couldn't get pins 4, 7, 8, 9 and 10 to be PWM outputs. So I set it to pins 0, 4, 7, 8, and 9. (Due to PPS mapping limitations).

*Brian


EmbeddedMan

Tue, 15 Apr 2014 03:13:18 +0000

Hi Brian, Thanks for the suggestion to use your software PWM library. I'm concerned about timing though, as this will be used in conjunction with a sensor acquisition system for musical performance that uses all analog inputs (and the remaining digital inputs), and I want to avoid jitter and/or latency in the sensor acquisition timing. Can your library handle multiple PWM outputs without affecting the overall loop timing too much? Thanks -- chaco

Yup. It actually does amazingly well, because the PIC32 is so freeking fast. There is very little jitter except under certain circumstances that don't normally show up often. And the library doesn't use very much CPU time either, unless you start using LOTs of I/O pins for it (like > 20 or so). For example, I think I put RC servo outputs on 82 I/O pins at once and I think it used less than 25% of the CPU.

So, feel free to give it a try and see if it meets your needs. If not, I can send you the updated files (there are I think just 3) that you'll need to get real PWM working on your Mini.

*Brian


chaco

Tue, 15 Apr 2014 03:17:47 +0000

Hi Brian -- Thanks for the info -- that's very helpful. I'll give it a try and let you know how it goes. I would still be interested in the hardware PWM at some point. Is this something that will be folded into an MPIDE update? There seem to be many small fubarino things that need tweaking (analog pin numbering, etc.)

Thanks again -- chaco


EmbeddedMan

Tue, 15 Apr 2014 03:45:40 +0000

Yes, absolutely. This change will be in the next MPIDE test build, whenever that happens (likely soon - next couple weeks if not sooner). If there are other things you find wrong, please log issues in the Fubarino Github issue tracker, or record them here, so that I can take care of them as soon as possible. And many thanks for finding the PWM issue.

OK, so here's what you need to do to update your MPIDE installation to use the new files.

Download the pins_arduino.h file from this link: https://github.com/chipKIT32/chipKIT32-MAX/raw/master/hardware/pic32/cores/pic32/pins_arduino.h and put it in the /hardware/pic32/cores/pic32/ folder.

Then download both of these files: [url]https://github.com/chipKIT32/chipKIT32-MAX/raw/master/hardware/pic32/variants/Fubarino_Mini/Board_Data.c[/url] and [url]https://github.com/chipKIT32/chipKIT32-MAX/raw/master/hardware/pic32/variants/Fubarino_Mini/Board_Defs.h[/url] and put them in the /hardware/pic32/variants/Fubarino_Mini folder.

Then rebuild your sketch that uses analogWrite(), and you should be good to go.

BTW, to test that this code works, I used the following test sketch:

int x = 0;

void setup()  {
} 

void loop()  { 
  analogWrite(0, x);
  analogWrite(4, x);
  analogWrite(7, x);
  analogWrite(8, x);
  analogWrite(9, x);
  delay(100);
  x = x + 8;
  if (x > 255) {
    x = 0;
  }
}

*Brian