Welcome in the forum!
We had this software-pin-toggle-discussion here in the forum a couple of times, mostly by users that just started using PSoCs.
The result was: Yes, you can do it faster by using some asm instructions, but what for? PSoCs are not MPUs only, PSoCs have internal hardware that is routable just as if you are designing electronics with a CAD-software.
PSoC internal signals can be routed to pins and use frequencies up to 24MHz.
So start "Thinking PSoC": Which parts of my project can be done in hardware using the components? Which parts have to be done in software?
And if that is not enough: You can define your own hardware using a Hardware Description Language (HDL) named VeriLog to describe special functions that run in hardware at 48MHz.
Some more: There are UDBs containing a small programmable ALU (Arithmetic and Logical Unit) , FIFOs to store data and some registers.
When you get all this, who asks for the toggle frequency of a pin in software?
That's all well and good, but I just want to determine the fastest way I can toggle a pin in software using PSoC's MPU. I am trying to evaluate a number of microcontrollers to determine the fastest way I can do this, for the cheapest price. It is for an application where I don't need the other PSoC fancy stuff, I just need to evaluate a few logic rules and toggle a pin based on them.
So, how would I go about doing it faster in asm? When i searched, it seemed like this method mapped to the fastest asm instructions, but it still seems slow compared to the 48MHz clock.
odissey1: great link, watching it now
Did you set the optimization to something better than "None"? (Project -> Build Settings -> Arm -> Compiler -> Optimization)
@Bob: Thanks, using an optimization flag got the square wave up to 2.29MHz... Could asm do anything beyond that?
@Dana: Isn't that the exact method I'm using?
Yes, of course: keep the values you want to write to the port in two registers and loop. two move instructions and a jump.
But you will not reach 10MHz this way and you have no control about the frequency, start or stop of the output.
Sorry I did not look closely at your approach.
The for loop lots of overhead, so an ASM approach would, I think, be
faster as its a move imeadiate (twice) followed by a short jmp.
Look at the .lst file and you will see all the cycles eaten up by the C
Clearly if you need speed and you still want MIPS for other stuff use
the PSOC HW approach to pin toggling.
When using the PSoC internal hardware you are able to control (start, stop, change period, change duty-cycle) a signal in the MHz range with a reaction-time of a few µs. CPU load is needed only for the changes, the component runs free as configured without any further intervention. When the algorithm for changing one of those parameters is simple logic, this can be accomplished in hardware, too. This logic is evaluated within a few ns when a look-up-table (LUT) component is used, cannot be beaten by any software design.