chipKIT® Development Platform

Inspired by Arduino™

UC32 speed

Created Fri, 08 Aug 2014 22:07:49 +0000 by lowfrequency


lowfrequency

Fri, 08 Aug 2014 22:07:49 +0000

Hello to the group. My first post. I am new to the arduino and the UC32. The intent for the UC32 is to use it as a 60KHz digital phase lock loop (DPLL). I used the official blink program without delays and somewhat expected very short cycle times. Hoping in the 10 to 20 Mhz 100-50ns range but it ran at 400ns. or a bit over 2 Mhz. I am surprised by this because thats on par with a Parallax SXB at 75 Mhz running basic. It would seem that using C is as bad as using basic. I sense that I have to go to assembly language and thats the point that I am getting really mixed up. Do I download the PIC IDE and essentially blow away the UC32 bootloader? I had really hoped to operate at a higher level in programming. (Thats called lazy) Thank you in advance for your help. Regards


majenko

Fri, 08 Aug 2014 22:24:40 +0000

No, you don't really need assembly.

The thing with programs like BlinkWithoutDelay is they use the chipKIT API calls to do all the work, and they are slow. They're slow because they have to do a lot of work. There's a surprising amount of effort that goes in to making a simple digitalWrite() function work in all situations.

But, if you aren't wanting all that overhead, you can directly manipulate the IO ports yourself, from inside C. Just write to the right registers.

For instance, on the UC32 digital pin 2 (for the sake of example) is port D8.

You can, instead of using pinMode() to set the pin to an output, use:

TRISDCLR = 1<<8;

That has the effect of clearing bit 1 of the TRISD register, turning pin 5 into an output.

Then you can turn the pin on and off with:

LATDSET = 1<<8; // Turn it on
LATDCLR = 1<<8; // Turn it off

All the pin-to-port mappings are listed in the UC32 user manual.

If you do find you need assembly, then you can embed it in your C code directly - no need to play around with other IDEs or ditch bootloaders or anything. This page is a good guide: [url]http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html[/url]


lowfrequency

Sat, 09 Aug 2014 14:58:48 +0000

Thank you will give that a try. Hope today. I will be travelling starting tomorrow so unlikely able to reply. At least for the moment I hope to stay at the c level and will look at the inline assembly. Regards


lowfrequency

Sat, 09 Aug 2014 18:04:22 +0000

I did get a chance to experiment. Simply using the code you sent I get a High of 12ns, Low of 13ns. Both close to 80 Mhz using a tektronix 2465 scope. The loop is slow at 386ns or 2.8Mhz approx. I expect the code to crush the simple on off operation. Essentially I need to build a phase lock loop and phase accumulator. So now I get to dive into the real experiment. Thanks


Lara222

Mon, 24 Nov 2014 11:55:57 +0000

Hi, i have developped a program (Chipkit UNO32 & MPIDE) which uses the Input Capture 1: :P