The code executes (I can see pin 9 go up and down).
The trouble is that the pulse I see on pin 9 is extremely short. Changing the count in the delay code has no effect.
Change the code to a sequence of NOPs, no change, pulse delay/time is the same.
Put a delayMicroSecond(?) before the second DigitalWrite and the pulse delay/time is increased.
It would appear that the ASM code is not being executed.
Any ideas, suggestions?
Can anyone tell me how I can get an assembler listing from the sketch compile so I can perhaps work out what is going on?
for (ctr = 0; ctr < MaxPulse; ctr++)
{
// Assumption, PulsePin = LOW on entry
// Duration of pulse: At clock of 16MB we need 200 clocks to generate a 40K signal
// Each half cycle is 12.5 Usec, sort of......
digitalWrite(9, HIGH); // (PulsePin, HIGH);
// Debug - nops only.... or the following loop code
asm("nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
::);
You're using a really slow function to turn the pin of and off, and then trying to diddle for a new nanoseconds between the calls, and see a noticeable delay? On an oscilloscope, I hope. I don't think that the smiley helps...
The smiley was not my doing, it apprears to be an artifact of the code and perhaps not inputting the code as "code".
I have an old but good osciliscope with two channels. Can see things down to nanosec.
I have managed to access the assembler code. Looks ugly but hopefully it will be a learning experience and I will benefit from grinding my way through it.
I note a couple of responses while inputting this so....
I need a delay of 12.5 U-sec.
The DEC-BRNE loop is 3 instruction times.
(1+2( dec, brne))*(1000000/16000000) = 0.1875 u-sec per loop.
For 12.5 u-sec the loop count is 67 (rounded).
I see around 1.5 u-sec on the osciliscope with only the dec-brne ASM code . Same if i include all the NOPS.
I include the assembler code around that area. I have not examined it in detail, yet.
My example in my post is to make two pulse and a delay ( the looping delay ), it work but I did not kow how to use JMP , a Forum member help me out to use JMP. I use while (1==1) to loop faster not throught void loop(). ( take too long )
Thank all of you for the responses and the interest.
The problem was the lack of VOLATILE on the ASM statement. It would appear that without the volatile my code was optimised out.
Add the volatile, recompile, re-load the 328. The ASM code looks good and I can control the pulse width/s by changing the value fed into the DEC-BRNE loop/s.
Looing at assembler code can sometimes be informative......
I had attempted to use the "digitalWriteFast(PulsePin, HIGH)" to set the PulsePin high and reduce overheads. This did not work, the code is
256: 85 b1 in r24, 0x05 ; 5
258: 82 60 ori r24, 0x02 ; 2
Woops, nothing set back into the port. Something else to chase....
However, I am progressing, once again thanks to all, Ian.