Fast square wave on gpio

I downloaded the gpio demo example for VF61 to explore the functionOutputDemo() functionality under WinCE6.
Everything seems ok (on a large time scale) if I leave the instructions Sleep(500)
In this way a 1 second square wave is generated (500 ms high / 500 ms low).

If I change them to Sleep(1) I would expect a sqare wave 1 ms high/1 ms low but this is not waht happens.
First of all the IO pin toggles every 2.5 ms (more or less).
Moreover (and this is the biggest issue) after 100 ms of toggling, the IO pin stays freezed for more or less 50 ms.

I suspect the behavior is related to the WinCE OS, but I wonder if it would be possible to generate a “fast” square wave on GPIO pin under WinCE.
Which is the minimum value for the period of the square wave?
How can I implement it?

My target is to implement a communication protocol over a parallel bus and I need some speed.

I’ve just discovered that the “50 ms freeze” is produced when Remote Display v2 over active sync is running.
Is this an expected behavior?

So I think we can forget this issue and focus on the minimum duration for the period of the square wave. I’m going to do some test with the application id debug vs release


You can try to increase priority of the thread toggling. But please note with 1ms most of the other things that are on lower priority will not work properly ( like Ethernet ).

Also toggling this fast you should access the registers directly not using GPIOlib. Maybe you MemMapLibrary to map GPIOs you need to user mode and toggle bits there directly. But still 1ms is quite optimistic.

where can i find GPIO and respective addresses for MapMemLibrary and example of it?

Dear @vix

Sleep(1) waits at least 1ms. And as the scheduler switches tasks on a 1ms tick base, this ends up typically in a cycle of 2ms if you run Sleep(1) in a loop.
Sleep(0) or SleepTillTick() are other functions you might consider.

The register addresses are documented in the VF61 reference manual. When you start playing around with the GPIO registers, I recommend you open the GpioConfig Tool in parallel, to easily monitor whether your code has the desired effect.

If you need a faster and more precise control over the GPIO toggling, you could consider using the additional M4 core inside the VF61 to generate the square wave.

Regards, Andy

Hi @andy.tx

even if this topic is quite old ;-), thanks for your answer.

I’ve learned a lot of new things in the meanwhile and so I can say that my original approach was wrong.

The right one is to use the proper hardware peripheral of ARM, configuring it with the proper library.

For this specific need, the best hardware peripheral is PWM that can be configured as needed both from A5 or M4 core. Once configured, the square wave is generated with the right timing.

Using a GPIO to generate a square wave is only a quick example to show GPIO usage.