SX/B Elementry coding
Rsadeika
Posts: 3,837
The following is a modified freqout.sxb program.
When I run this program with the sx key, the LED turns on for two secs and then turns off. What is supposed to happen is when it detects an object, then the LED is supposed to turn on.
Now, when I remove the sx key, and run the program, it works the way it is supposed to. Is their some major concept that I am missing here?
'
' Device Settings
'
DEVICE········· SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000
'
' IO Pins
'
IrLED··VAR·RB.6···' output to IR LED
Detect··VAR·RB.7···' input from IR detector
LED1··VAR·RC.7···· 'LED (green)
'
' Constants
'
IrMod··CON·38000···' modulation freq = 38 kHz
Yes··CON·0·' for active-low output; Yes, detected
No··CON·1·' No, not detected
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
· freqout IrLED, IrMod, 1
· if Detect = No then Start
· low rc.7·'If yes, then turn on the LED
· pause 2000
· high rc.7·'Turn off the LED
end
·
When I run this program with the sx key, the LED turns on for two secs and then turns off. What is supposed to happen is when it detects an object, then the LED is supposed to turn on.
Now, when I remove the sx key, and run the program, it works the way it is supposed to. Is their some major concept that I am missing here?
'
' Device Settings
'
DEVICE········· SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000
'
' IO Pins
'
IrLED··VAR·RB.6···' output to IR LED
Detect··VAR·RB.7···' input from IR detector
LED1··VAR·RC.7···· 'LED (green)
'
' Constants
'
IrMod··CON·38000···' modulation freq = 38 kHz
Yes··CON·0·' for active-low output; Yes, detected
No··CON·1·' No, not detected
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
· freqout IrLED, IrMod, 1
· if Detect = No then Start
· low rc.7·'If yes, then turn on the LED
· pause 2000
· high rc.7·'Turn off the LED
end
·
Comments
Also realize that when you are checking "Detect" the freqout has stopped, so unless the detector stays on for a little while after the IR stops you may not detect anything. (But I think it will stay on long enough.)
I would also put a "INPUT Detect" to be safe.
You should also change the osc setting to OSCHS2 for 50MHz.
'
' Device Settings
'
DEVICE········· SX28, OSCHS2, TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000
'
' IO Pins
'
IrLED··VAR·RB.6···' output to IR LED
Detect··VAR·RB.7···' input from IR detector
LED1··VAR·RC.7···· 'LED (green)
'
' Constants
'
IrMod··CON·38000···' modulation freq = 38 kHz
Yes··CON·0·' for active-low output; Yes, detected
No··CON·1·' No, not detected
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
· input Detect
Main:
· freqout IrLED, IrMod, 1
· if Detect = No then·Main
· low rc.7·'If yes, then turn on the LED
· pause 2000
· high rc.7·'Turn off the LED
· goto Main
end
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.TerryHittConsulting.com
Post Edited (Bean) : 2/11/2005 7:14:46 PM GMT
One of these days, I'm going to measure how long it does stay on.
I would suggest the following:
FREQOUT IRLed, IRMod, 1
DetectVal = Detect
IF DetectVal = 1 THEN GOTO Start
...
This would 'unwrap' the reading of the pin from the 'IF' statement.
I'm not sure this would solve your problem -- you still need to read the IR-Detector pin within a very short time (200 uSec?) after the pulse ends -- and the SX-Key environment may or may not support that.
You might also want to put a 'PAUSE 1' before the FREQOUT.· I'd put this in to allow the IR-Detector to 'settle' a little.· The SX runs really fast -- I don't know what the 'ping' rate is of the tight loop you've built, but it sounds like under the SX-Key the pin is always low, ie the Detector is always active.· That can't be right.
Post Edited (allanlane5) : 2/11/2005 9:05:37 PM GMT
I appreciate your suggestion, but the project I am working on will be run in stand-alone config. So, I do not want to add code as a work around to enjoy the convience of a run with the sx key installed. Eventually I expect the code to grow, so I want to keep the code as tight as possible while it is still in the early stages.
How exactly are you trying to run it with the sx-key ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.TerryHittConsulting.com
·
While I am on this subject, would you have any coding suggestions as to how to make the program work using an interrupt concept. The example in the SX/B examples dir leaves a lot to be desired.
Timing loops in SX/B are frequency dependent. Rsadeika, you have a seperate thread going on about this. Are you sure that you've got the various run frequencies straightened out between with the Key and without?
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
As to the reflected signal from the sx key; does any body know if an sx key has the capability to send an IR signal.
In my project I will be using the sx tech board exclusively, and the same sx28 chip will remain in place. Since I will be doing some reprogramming, it would be nice to be able to run the program while the sx key is installed, and still get the same results after the sx key is removed.
If that is not the problem, then there is no reason the program shouldn't run properly from the sx-key.
Try the program with the freqout commented out. You may want to put a pause in it's place. See how that runs with and without the sx-key.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.TerryHittConsulting.com
·
I tried replicating the program using an interrupt scheme, and the same problem occurs. And of course their are new problems that have crept in.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.TerryHittConsulting.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
1. With sx key installed, my signal LED goes on imediately, and placing objects in front of the detector has no affect what so ever.
2. Without the sx key installed (stand-alone), my signal LED works as expected. Placing and removing of objects, the signal LED goes on and off accordingly.
3. With the sx key installed (stand-alone), but no comm cord attached, nothing works. No immediate turn on of signal LED, and placing objects in front of the detector has no affect.
In this set-up I was expecting some sort of activity. I tried other simple programs, and in a stand-alone condition the experiments worked with or without sx key installed, in all variations.
Now I am thinking, is their a subtle code variant, in the freqout command, at the assembly level, when, in combination with the sx key installed, odd things start to occur. When I did a debug, the code listing is to complicated for me to make any sense of it.
So far I think that I have ruled out any kind of IR frquency reflection, I have double checked all of my wiring on the breadboard, and I believe that all my componets are working correctly.
Again I plan to use the SX Tech board exclusively, so I want to make sure that every thing responds in a predictable manner.
1) IR remote receivers are notoriously susceptible to RFI (interference). How about removing it from the system, and tying your SX pin to either ground, or power, through a switch. This should give you a hint whether it's a hardware or a software problem.
2) Super!
3) With an SX Key, but no serial cable, you'll get no clock (how would it know what speed to clock at, without access to the PC?).
When you say you have the key unplugged, what are you doing for a clock? (Is there any way you can get access to an oscilloscope? This would be trivial to solve if you did (probably)).
Steve
If I remember correctly I have done this to go back and forth between the SX-Key and the BS2.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out· the "SX-Video Display Module"
www.TerryHittConsulting.com
·
there's something really rough, 37 MHz or so, unstable, and 100mV tall, but nothing like the proper clock signal.
(The SX-Key will continue to generate a clock once it's been set up by the software, but from a cold power-on, mine definitely comes up silent). I don't believe that it's broken. (After all, the Key can't possibly know what frequency to run at until told. I favour silence, over just picking a frequency that will cause confusion)
Steve
The other suggestion, I do not have the electronic background to attempt something like that. Besides, I think that the Parallax tech people should be investagating that, and saying whether a problem like that would be remotely possible, and if it is possible, then a tech note would be in order (maybe their is a tech note in existence, I have not read all of the documentation yet). But, that is just my opinion.
I have written some code using my IrLED-Detector example where I placed the freqout in an interrupt scenario. The program works, but the timing is off for the pause statements. When I code 'pause 1000', in real time the pause is about four seconds. Any ideas as to what to look for; in the documentation it talks about interrupts, and added cycle time. I thought the beauty of SX/B is that it does a lot of the balancing act for you.
Steve
Before I start working on trying to make an IR remote control work with my experiment, I will post the components that I am using , and some approximate values for the IrLED-Detctor.
The components are standard Parallax issue:
350-00017 - Shrink wrapped IR LED
350-00014 - 40 kHz IR Detector
150-02210 - 220 resistor
The values:
kHz distance
37500 - 5 inches
38000 - 6 inches
38500 - 6 1/4 inches
39000 - 6 1/2 inches
40000 - 7 inches
41000 - 7 1/4 inches
42000 - 7 1/2 inches
43000 - 7 inches
44000 - 5 1/2 inches
45000 - 5 inches
The method:
I used the 'old science' method, a piece of paper as the object, and a tape measure with my eyeballs to determine the distances.
I hope this saves some time for somebody. Again, these are approximations, plus/minus a quater of an inch.
Does this mean that your project now works properly with the Key, or are we still hunting problems?
(Also, note that IR detection like this really isn't a very reliable way of measuring distance, since it depends much more on the reflectance (and orientation) of teh object than it does on the distance. If you're trying to do things liek folowing walls at a set distance, you might be disappointed).
The only reason I posted the chart is for some neophytes like myself who ask the question, what kind of distance are we talking about. Is it 6 yards, 6 feet, 6 inches, or 6 mm. I am also aware of the reflection qualities of the object. Maybe I should use a black piece of cloth as the object and see what the differences are. Or maybe some experts out there can write some tight code that determines the reflective quality of the object and adjusts accordingly.
If it's not a clock speed issue, then it's likely to be some subtle effect that will bite you when it's least convenient, and you might as well hunt it down now. Replacing your IR receiver with a bit of wire is hardly a huge investment in time or effort, and should let you see if it's a hardware or software problem. If you can't be bothered to chase it, fair enough.)
As for the distance sensing, determining distance by the amount of reflected light is a doomed enterprise unless you can control the target. Measuring distance by, err, measuring distance is a much better method. Sharp's GP2D12 (and other similar) sensors are a far better bet - they work by triangulating the angle of a spot of light, rather than a slightly related second (or worse) order effect). Sure, the reflectance approach is temptingly cheap, but I've never seen it work usefully.
Steve
You can't do that! It will cause all sorts of "interesting" effects including causing the chip to run at speeds that could cause the exact problem you are seeing.
The SXKey is a clock source. So is the resonator. Running the chip with both a resonator AND the SXKey installed is like trying giving the chip two bosses and watching it have a nervous breakdown.
I don't know where parallax documented it or how bold they made it, but I KNOW you can't do that and expect correct operation.
Disconnect the resonator, connect the SXKey and then try again. Better yet, have you ever been able to step through the program with the SXKey? E.g. Debug mode rather than just Run mode? This should be a pleasent supprize for you if you haven't seen it before.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
As for your single wire suggestion it reminds me of the previous experiment.
I took the code out of the Daubach book that pertains to the IrLED-Detector for his SX tech bot, midified the code a little bit so it would use just one IrLED-Detector combination, and ran the code. I was thrilled that when it was running, that when I placed my hand in front of the detector, my test LED would go on, and when I removed my hand, the LED would go off. Then I decided to start debugging, I put my finger over the IrLED, and moved my hand in, the test LED turned on. I blocked off both the IrLED and the detector, hand in LED on. At this point I started to remove all the pieces from the breadboard one at a time, HAND in LED on. I finally ended up with my test LED and resistor which was hooked to rc.7 and a wire stuck in rc.6, when I moved my hand toward the test LED the LED would turn on, and when I moved my hand out, the LED turned off. At this point I was thinking about getting a video input card hooked up to a TV set, and the tech board, to see if I could dial something in. Now, I am not implying that their is anything wrong with the Daubach code, the complexity is why I switched over to SX/B, after discovering the freqout command.
If you looked at my code example you can see that it is very straight forward, with the minimum amount of code lines to do the job. So, I am getting all kinds of different outcomes, some of which defy logic while some of which, confirm equipment stability.
I am planning to use SX/B for the quick gratification aspect, then on a parallel write code in bit-banger. I prefer bit banging, but their is a learning curve to overcome.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
Does it flash at the same speed with the SX-key and the resonator?
You seem to be trying to solve a lot of problems at the same time, and I'm not sure how much they're related.
Since your program relies on accurate frequency control, I'd keep trying to get the SX-key version to work, since that'll get you the useful debug features. Also - have you considered sticking a LED and resistor on the output of the IR receiver, so you can actually see what's going on. At the moment, you don't seem to know whether you've got a design, implementation, software or hardware problem, and you can't trust your tools. It's time to stop, and remove as many variables as possible. (Or you kood keep on changing stuff, and hoping. It's your project, and your time [noparse]:)[/noparse]
Steve