Use "setfreq" within a subroutine.

jims

Senior Member
Should I be able to use a "setfreq" command within a subroutine in order to change the frequency and run faster or slower within that subroutine? Or can it only be set during a download?
Thank you, Jims
 
Last edited:

srnet

Senior Member
Not sure what you mean by "can it only be set during a download", but you certainly can use SETFREQ within sub routines.

Do a simple flash an LED test .............................
 

jims

Senior Member
srnet...since I usually put my "setfreq" before the main program, it is only run during a download. Also, I never seem to do things in a simple manner.. I came-up with this program to ...Do a simple flash test. Any comments about how this can be simplified. I'd appreciate your input,\. Thank you, Jims

Code:
'*** 20x2 running diagnostic to test 
'*** using "setfreq" in subroutines.

symbol LED=B.2    'pin 16  green wire

#Picaxe 20x2
setfreq M4
main:
	do
	setfreq M4
	pause 2000
	call set8
	call set16
	call set32
	call set64
	loop
		
set8:
	setfreq M8 
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	setfreq M4
	pause 1000
	return
	
set16:
	setfreq M16 
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	setfreq M4
	pause 1000
	return

set32:
	setfreq M32 
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	setfreq M4
	pause 1000
	return

set64:
	setfreq M64 
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	pause 500
	toggle led
	return
 

srnet

Senior Member
Well for one, the program is downloaded as a whole, and then executed, there is no concept of commands running before or during the program download.

The setfreq you have above, before Main:, is executed after download, when the program first runs.

try this;

Code:
Main:

gosub flash4
pause 2000
gosub flash8
pause 4000

goto main

flash4:
setfreq M4
for b0 = 1 to 5 
high LED
pause 500
low LED
pause 500
next b0


flash8:
setfreq M8
for b0 = 1 to 5 
high LED
pause 500
low LED
pause 500
next b0
 

jims

Senior Member
Well for one, the program is downloaded as a whole, and then executed, there is no concept of commands running before or during the program download.

The setfreq you have above, before Main:, is executed after download, when the program first runs.

try this;

Code:
Main:

gosub flash4
pause 2000
gosub flash8
pause 4000

goto main

flash4:
setfreq M4
for b0 = 1 to 5 
high LED
pause 500
low LED
pause 500
next b0


flash8:
setfreq M8
for b0 = 1 to 5 
high LED
pause 500
low LED
pause 500
next b0
Thanks; srnet...I'll try it. Sure is much simpler. Jims
 

srnet

Senior Member
The only Gotcha with using SETFREQ I have come across, is doing a SETFREQ then immediatly followed by a Sertxd or Serout, a slight pause might be needed to allow for the clock to stabilse so the outgoing baud rate is spot on ..............
 

westaust55

Moderator
Well for one, the program is downloaded as a whole, and then executed, there is no concept of commands running before or during the program download.

The setfreq you have above, before Main:, is executed after download, when the program first runs.
I suspect that jims confusion comes about from “commands” such as DATA or EEPROM and TABLE which are PE directives and only acted upon at the time of program download. Most but not all PE directives have the hash (#) character which helps to distinguish from BASIC program commands.
 
Top