Noob Question...
Fabry
Posts: 7
in BASIC Stamp
Hi there,
so, I'm new to BS, and I have a little question for you All.
I'm try to run a very simply routine as below:
do
pulsout 14, 6000
pause 20
pulsout 15, 200
pause 20
loop
I need a frequency of 50hz with around 50% duty on PIN 14 and a frequency of 350hz around 50% duty on PIN 15....in the same moment.
So, is very simply routine...but I have a problem... the instructions are followed line by line from the BS2...and the result is that the pulse on the pins is the same, for example on PIN 14 I have a pulse of 50hz with duty of 30% and on PIN 15 I have a pulse of 49hz but with a duty of 80%.
So, I think the problem is because the BS2 flow the routine line by line...but this is not right for me.
How I can do for have the right result?
Thanks for your help, and sorry for the very noob/stupid question.
Regards
Fabry
so, I'm new to BS, and I have a little question for you All.
I'm try to run a very simply routine as below:
do
pulsout 14, 6000
pause 20
pulsout 15, 200
pause 20
loop
I need a frequency of 50hz with around 50% duty on PIN 14 and a frequency of 350hz around 50% duty on PIN 15....in the same moment.
So, is very simply routine...but I have a problem... the instructions are followed line by line from the BS2...and the result is that the pulse on the pins is the same, for example on PIN 14 I have a pulse of 50hz with duty of 30% and on PIN 15 I have a pulse of 49hz but with a duty of 80%.
So, I think the problem is because the BS2 flow the routine line by line...but this is not right for me.
How I can do for have the right result?
Thanks for your help, and sorry for the very noob/stupid question.
Regards
Fabry
Comments
You're right, each instruction is executed in sequence. But you can do something else that works up to about 500Hz. See the sample code below, which gives 350Hz and 50Hz on my BS2.
This is where a Propeller will do the job for you. You can have one cog produce the 50 Hz stream and have another cog produce a 350 Hz stream without any conflicts.
First of all, Thanks a lot for all your answers!
So, I will try with the code of Sapphire, but I look the propeller, and i think the Propeller Mini is ok for me.
Just...I need to connect a EEPROM externally?
Hi Tom,
so, about the eeprom, I don't remember where, but I've read if I do't use a external EEPROM, once I shut down power the Prop lose the program...
I'm worng about this?
Ahhh, ok, now it's clear!
Thanks for help!
Hi Tom,
I try to add other insctruction on your program, like this: Freq.Synth("C", 7, 350).
But the program doesn't work.
Can You explame me why?
Other problem that I've encountered is:
I try to have 3 frequencies when I push 3 different button:
push first button = first freq
push second button = second freq
push third button = third freq
How can I do this?
Sorry but I've read the tutorial on Propeller SW, but I can't understand. So, the propeller is too difficult then PBasic...
Each cog has access to two "synthesizers" (counter logic). They are referred to as "A" and "B". So to answer your first question,
Freq.Synth("C", 7, 350) doesn't work because there is no "C" synth. In a perfect world, it wouldn't even compile.
If you want just a single frequency at a time, you could do something like:
If you want two frequencies at a time, you could use the "B" synth in the above fragment to suit yourself.
If you want more than two frequencies at once, you will have to start an additional cog. Have a look at cogstart, etc in the manual.
Your main loop might look like:
So, I've make a mash-up of both the code in this thread:
But I have a problem...the pin 10 doesn't work. Other pins, 11 and 12, work perfectly, but 10...NO. I dont understand why.
Any suggestion?
Sorry, but I've not understand the functions of (WAITCNT), (button and previous).
Right, the routines work well (for my use) without the functions mentioned.
So, I need to have a signal present in the same time that I power the propeller, and I need to have the possibility to choose a freq. with the buttons on other pin.
I use a rotary switch instead 3 buttons, like to AUTO, LOW, MED, HIGH functions.
So, I've tried to put a routine that stops all the functions except the Freq.Synth("B",1,25), but I'm not so clever with propeller...it's too hard then PBasic...
Most likely your P10 button circuit is faulty.
WAITCNT is similar to the PAUSE command.
The Propeller has a Count register called CNT that counts up on each clock cycle or "tick".
Wire each Rotary switch position to an I/O pin just like it was a pushbutton and connect power to the common pin.
Just remember to put a long delay in your program so you see the final switch position and not on of the changes.
If you can use PBASIC then you can use Spin.
It's a very easy to use language and the Propeller Education Kit text will teach it to you step by step.
https://www.parallax.com/downloads/propeller-education-kit-labs-fundamentals-text
https://www.parallax.com/downloads/propeller-education-kit-labs-fundamentals-example-code