Newbie, help needed
Scooter
Posts: 11
Hello, after several (simple, but working fine) projects using the BS2 module, for my new project i need a Propeller.
I'm at the very first step about learning how to program in Spin (i'm only able to do basic I/O functions), so please
be patient..
My project is to control an R/C tank using a custom electronic, basically what i would like to obtain at the moment
is to read four channels from a receiver (typical 1 to 2 mS) and do different actions according to the signal decoded.
I rolled around Post and OBEX and i found the RX & RX_demo OBJ that i modified to read only one channel, but now
i'm stuck about reading and compare the [pulseOut] stored in phsa register...
I'm sure i made some mistake or missed something but where ?
Thanks to all for the help and sorry for the bad english...
Ivan
Here's the modified code :
I'm at the very first step about learning how to program in Spin (i'm only able to do basic I/O functions), so please
be patient..
My project is to control an R/C tank using a custom electronic, basically what i would like to obtain at the moment
is to read four channels from a receiver (typical 1 to 2 mS) and do different actions according to the signal decoded.
I rolled around Post and OBEX and i found the RX & RX_demo OBJ that i modified to read only one channel, but now
i'm stuck about reading and compare the [pulseOut] stored in phsa register...
I'm sure i made some mistake or missed something but where ?
Thanks to all for the help and sorry for the bad english...
Ivan
Here's the modified code :
VAR
long Stack[20] 'Stack space for new cog
PUB Measure (pulseOut)
{{Continuously acquire pulse width on the pin at address pinIn,
and store as microseconds at the address pulsesOut }}
ctra[30..26] := %11010 ' Set mode to "logic A"
ctra[5..0] :=0 ' Set input pin 0
frqa := 1 ' Increment phsa by 1 for each clock tick
repeat
waitpeq(|< LONG[0], |< LONG[0], 0) ' Wait for pulse to start
waitpne(|< LONG[0], |< LONG[0], 0) ' Wait for pulse to stop
LONG[pulseOut]:= phsa /(clkfreq/1_000_000) ' Calculate Width, in microseconds
phsa := 0 ' Reset the counter
Comments
http://www.parallax.com/tabid/726/Default.aspx
When you post code, place your code between code tags, like what you see below but be sure to remove all of the spaces I placed between the brackets.
[ code ]
[ / code ]
Without the code tags, the indentation is lost and it's hard to read your code.
Thanks
Hello Kevin Brown, i followed your link but no code at all...
Thanks
Ivan
CODE not QUOTE
code looks like this and keeps all the indention which is an essential element of the codestructure
as the indention is lost through QUOTING I guess you meant it that way:
for a precise clock you should always use these constants
like shown in the CON-section
the value of xinfreq must match the frequency of the chyrstal you are using
if you have a chrystal with more than 6.25 MHz PLL-mode 16x is not possible
f.e. with an 8 MHz chrystal you should use
_clkmode = xtal1 + pll8x
there are several objects in the obex for receiving servo-signals
best regards
Stefan
Sorry i made a mess with the insert buttons.
Yes the code is just like that, i'm using a 5 MHz crystal and i put the CON statement in the code, i compiled and downloaded into Propeller with no errors, my problem is how to compare the value stored in variable [pulseout] with another value. What i would like to do is to use a COG for each of four RX channel monitored, using it to compare the value in mS of the stick position i.e.
1.5 mS (neutral) : do nothing
from 1.6 to 1.750 mS : move a servo (or simply turn on a led)
from 1.9 to 2.0 mS : move another servo (or turn on another led)
But i'm not sure that a simple "IF (pulseout) > 1_600_000 AND < 1_800_000 then do something" is correct and works, also i was asking me if a single COG for every channel is the right way, with this code the COG always measure and store and must be called out from repeat for compare the results and turn on leds... maybe i should use a COG polling the other four.
Another question is : the RX supply is around 5 VDC the signal that usually is feed to a servo has this amplitude, reading various posts someone says "use a level translator 5V - 3V" someone else says a 4K7 to 10 Kohms is enough, at the moment i have connected the RX channel to pin 0 through a 4K7 resistor.
Thanks for the help
Best Regards
Ivan
http://www.parallax.com/tabid/704/Default.aspx
It's holyday and i have some spare time for try to learn some more.
Reading the docs found into parallax homepage i used these two codes to read a RX ppm signal, but i really don't understand how to compare "tHprobe" variable to another fixed value as i wrote in a previous post, there is someone that can explain me how to do?
Thanks a lot
Ivan
If two variables are integers, then you can use binary operators like > or =>, etc. (see page 43 and 170, 171, etc of the Propeller Manual).
But if the variables are not integers, then you'll need to use one of the FloatMath32 objects for FCmp.
http://obex.parallax.com/objects/202/
or maybe:
http://obex.parallax.com/objects/689//
Of course, if you must compare two numbers like 1.75 and 1.15, you can multiply both by 100 and compare them as integers instead of using FCmp for decimals.
Is this what you're asking about?
simple compare
Hello Mike G
Yes, this is what i would like to do and where i'm stuck...
i have a precise 1 mSec ppm signal connected at pin 0, i have (called at the end of the PwmMonitor OBJ code) a led blinking and i'm assuming that the code runs.
In the Main (as posted below) i have added the if/then condition to turn on a led when the signal applied is bigger than 1 mSec but it does'nt work.
Thanks
Ivan
When your program gets to the repeat statement, it will hang there forever and do nothing else. Is that what you want it to do?
i'm trying to test the code and try to learn instead of simply cut & paste, lighting up a led is to see if it works. (my simple project is to read a ppm pulse widht from one channel R/C rx an move 2 or 3 servos in different position i.e. for 1.7 mS input -> servo 1 full forward, servo 2 full backward and so on.
i added the repeat only to have the led turned on and be able to see it. (maybe is wrong).
i'm assuming that the repeat should always compare "data" with 1_000_000 an lit the led if data is bigger (and maybe is wrong also).
I know that my questions are "dumb" but i am trying to learn by myself using the tutorials and the language differences will not help (my english is poor) but here in Italy seems that nobody use this amazing chip or the Basic Stamp.
Thanks
Ivan
This debug script might be of some help.
Be sure to work your way through the tutorials one step at a time so you are not biting off more than you can chew at any one time.
If you want your program to keep comparing your variable data to 1000000 in a loop, then you must place a repeat command something like this:
The waitcnt command will cause the program to wait at that point for 2 seconds so you can see your LED. See page 218 of the Propeller Manual for how the waitcnt command works.
Also, to get your LED to blink on only when data > 1000000, you'll need code to turn it off, too. Otherwise it will turn on and stay on forever.
As for your R/C problem, I'm afraid I don't know enough to help you with that. But I think you need to learn some more fundamentals about the code before rushing into complex functions.
Good luck!
Follwing ElectricAye hints i managed to go step by step, here's the code that works for my purposes,
if someone would like to look in and tell me if there's something (and sure there is) that can be made different (better) or much more fast and "skinny" i will be glad.
Ivan
MainPWM
PWM2
PWM3
PWM_elev_up
PWM_elev_down
PWM_recoil
PWM_turn_left
PWM_turn_right