PWMOUT on 20M2 Off Frequency

Armp

Senior Member
Once again I'm stuck with the simplest possible problem. (The hard ones I can usually fix)

I need to generate a 8Khz square wave to test a piece of equipment.

No problem, I thought! Used the PWM wizard, and got:

Code:
#picaxe 20M2					
#no_data
 		
pwmout B.1, 124, 250
Run it - nice square wave, but the frequency is 1 cycle every 15 seconds!

Yup - I got decoupling caps, pull downs, fresh batteries, cold beer and a headache.

What did I miss this time :confused:
 

Armp

Senior Member
Even after reading more thoroughly through Manual #2 I'm still not sure why "STOP" was required? Or where it's documented...

Maybe e,h or t can explain further please?
 

eclectic

Moderator
Have a look at
M.2, p. 64 (end)

and
M.2, p. 235 (Stop)

Otherwise, Stop and wait for a Grown-up to
provide a better answer.

But don't end. :)

e
 

inglewoodpete

Senior Member
@Armp, In response to a comment you made in another thread, I'll explain what is happening here.

This code will not provide PWM, the 'end' statement will kill all processes:
Code:
#picaxe 08m2 
#no_data

pwmout 2, 124, 250
end
As you discovered, the following code does not provide PWM either. The reason: the "compiler" in the PE always automatically inserts an "end" token after the last command of your code. So, after starting PWM, the invisible "end" token kills off all processes. I think the reason is to prevent execution falling through and executing stored data (data or table commands) or other remnant/random stuff in the program space.
Code:
#picaxe 08m2 
#no_data

pwmout 2, 124, 250
The following code examples all leave PWM running as a background task. The structures all prevent the invisible 'end' statement from being executed.
Code:
#picaxe 08m2 
#no_data

pwmout 2, 124, 250
do
loop
Code:
#picaxe 08m2 
#no_data

      pwmout 2, 124, 250
here: goto here
Code:
#picaxe 08m2 
#no_data

pwmout 2, 124, 250
stop
 

HertzHog

Member
Why was the cycle time 15 seconds originally? Before it speeded up with a stop. I can understand the implied end would terminate it differently than a stop.
 

Armp

Senior Member
Why was the cycle time 15 seconds originally? Before it speeded up with a stop. I can understand the implied end would terminate it differently than a stop.
That was what really confused me... If there had been no output at all I would have checked the code - but it happily sits there toggling about every 7 secs. Subsequent checking on a scope showed some additional pulsing activity during the low period.
 
Top