Why doesn't program work with < instead of >

abenn

Senior Member
A couple of weeks ago I was trying to find a way to determine if an RC receiver is receiving a signal or not. Pulsin didn't work because no signal seems to be different from zero pulse.

I put my DVM on the an output pin in the receiver and noted that the voltage read as zero when it was receiving no signal, and 0.2v when it had a signal. By trial and error I got the following code to work ... after a fashion: The LED comes on if the receiver is receiving a signal from its transmitter, and off if it isn't.
Code:
main:
loop:	 	readadc 1,b13
		if b13> 3 then led_on
		goto led_off

led_on:	high 4
		goto loop

led_off:	low 4
		goto loop
But initially I had used ... if b13< 3 then ... and it didn't work :( Why should that be? If I instruct it to do something if the value is greater than 3, then it should also work if I change the instruction to less than 3, shouldn't it? But it doesn't -- the led stays on whether the receiver is getting a signal or not :confused:

Also, I don't understand why a value of 3 works when I had measured 0.2 with my DVM on dc volts setting. If I use 4 the led stays on all the time. Am I not right in thinking that "256 different analogue readings ... over the full voltage range (e.g. 0 to 5V)" means that with a 5v input, 0.2v on pin 1 should result in a readadc value of about 10?
 

BeanieBots

Moderator
Oh dear! I thought we had got this sorted last time.
Obviously not.
As you don't want to take the path explained when there are no pulses, then you can use ReadADC but not the way you are trying to do it.

So what do you think the voltage of your digital pulses actually is?
Well, that depends on when you read it doesn't it!
Your DVM is averaging the voltage to give a reading.
The PICAXE will return a value that depends on when it took the reading.
That will be either very close to 0v or very close to whatever the pulse voltage is.

Try this:-
main:
readadc 1,b13
debug
goto main

You will find that b13 will be all over the place.
Then put a 22k resistor between RC signal and PICAXE input with a 100nF capacitor between PICAXE input and ground and try it again.
Then vary your RC signal and note the values for each stick position and use those values for your test.

Be warned. Depending on your RC equipment, you may find that ANY of the sticks might have an influence on the averaged voltage. That is because different equipment has different ways of treating the frame time. Also, the pulse rate will be different between RC brands so your "product" may not be transportable between different makes of RC.
Also, due to the averaging, the response time will not be any better than the special case of pulsin for no signal.
 

abenn

Senior Member
I'm sorry if I didn't understand some of the feedback last time, but I thought we had resolved then that no-signal is different from zero pulse, and therefore pulsin doens't work for detecting no-signal. My strobe circuit is working fine for signals within the normal RC pulse range, but not for the random noise when the receiver is not receiving a signal. Since it's good practice to always have the RC transmitter switched on while the receiver is on, I've left it at that so far as the strobes circuit is concerned -- I've used up all the code bytes allowed by my 08 chip anyway :)

So now I was just experimenting to see if I can use a PICAXE to detect no-signal, as opposed to zero pulse. My dvm reading was very steady, but that's presumably a function of how much smoothing goes on inside the meter. But, even though the circuit switches on and off reliably when I switch the RC transmitter on and off, when off it then gives sporadic flashes of the led which, as you suggest, is probably due to the randomness of the noise the RC receiver is giving out when receiving no signal. I had guessed that some kind of electronic solution was required within the circuit, so thanks for the suggestion of capacitor and resistor :)

I hadn't thought of using the debug function, and now that I've read about it in the manual I see how useful it can be. So I'll give that a whirl when I get the time -- probably not this weekend, so please don't expect a quick response. Presumably it should be "debug b13" in your suggested code ;)

While all that is good helpful stuff, for which I'm grateful, it's not what my question was: I initially tried the program using the less-than operator instead of greater-than. Since it switches the led on when b13 is greater than 3 and, hence, off when it falls below 3, why does the program not just work in the opposite sense when I use the less-than operator? If I use less-than it just leaves the led on irrespective of signal or no-signal :confused:
 

hippy

Technical Support
Staff member
While all that is good helpful stuff, for which I'm grateful, it's not what my question was: I initially tried the program using the less-than operator instead of greater-than. Since it switches the led on when b13 is greater than 3 and, hence, off when it falls below 3, why does the program not just work in the opposite sense when I use the less-than operator? If I use less-than it just leaves the led on irrespective of signal or no-signal :confused:
What's probably happening is that you are reading voltages which change frequently very rapidly and although the led may be going on and off you may be perceiving the Led to always be on. It may well be doing what is intended, just that you cannot see it.

If you put pauses after turning the Led on or off what's happening may become clearer. With low values of pause the Led may not be always on or off but its brightness should change. You can also try making the "3" value larger to see what affect that has.

For this sort of debugging you can use two Leds, one for signal present and one for signal absent. With these side by side you'll get a much clearer view of what's going on. This helps show the illusion of something being both on and off at the same time.
 

BeanieBots

Moderator
You are correct in your way of thinking about using <b13 or >b13.
It's just that the value being read will not be what you are expecting.
The reason is what Hippy said.

I STILL think the use of pulsin is your best option.
Go through the earlier thread again.
I know it works and can be done because I've done it.
I've made a Dalek which is RC when there is a signal and autonomous when there is no signal.
Like yours, my radio gives erratic short duration pulses when the Tx is off.
This actually helps because it provides a pulse for pulsin avoiding the long 0.6s timeout. (which needs to be handled as a special case if you have timed loops)
The only enhancement that I implemented that was not included in the code given earlier, is that I wait until at least 3 good valid pulses have been received in a row before assuming RC is present. I did that to avoid servo jitter that would happen everytime one of the "noise" pulses fell inside the "valid pulse" window.
 

abenn

Senior Member
I understand what you're saying, hippy, so I'll add another led to my test circuit as you suggest.

But surely, logically, if the fluctutating voltage is registering as either above or below 3 when I use the greater-than operator (which it does, because it switches the led as intended), it should also register, but in the opposite sense, if I use the less-than operator :confused:

When I get the chance next week I'll be implementing both yours and BeanieBots' suggestions, which may give me a better insight into what's happening :)
 

hippy

Technical Support
Staff member
Poke yourself with your finger and go "ow" when you do. Now repeat but go "ow" when you are not poking yourself.

Do the same again but poke yourself really fast; you'll be going "ow-ow-ow" in both cases and no observer can determine from that whether your going "ow" when you are poking yourself or when you are not.

It's not quite the same as that but it's the sort of effect I think you are seeing. Everything is happening as you expect it to, just that it's happening so quickly, and based on incorrect data as well, that the Leds ( more correctly your eyes ), and swapping < for >, do not reveal what is actually happening.
 

kym

Member
First enable the enhanced compiler in the options menu:

Then change the code to this:

Code:
 main:
    readadc 1,b13
    if b13> 3 then led_on
    goto led_off

led_on:    high 4
    goto main

led_off:    low 4
    goto main
Then use the simulator:
This simulates with > or < with no problems :

Kym
 

moxhamj

New Member
I do wonder if it is possible to actually troubleshoot these sorts of circuits without a CRO. I tried for many years and for only $130 I can now diagnose all sorts of things. Have just been playing with a 2Mhz divide by 2 flip flop circuit that stops working if a hand is nearby (stray capacitance probably). It is nearly impossible to diagnose things without a CRO. In the case above measuring the adc voltage of a narrow pulse is not going to be very reliable. Radio can do all sorts of strange things too - I've got two Rx modules that go into oscillations if they are near each other. Again, impossible to diagnose without a CRO.
 

andrew_qld

Senior Member
I actually had announcers at work complaining about getting "sore ears" when they were using a particular headphone amplifier. When the volume was pushed up I couldn't hear anything but the VU meter pinned and I got a headache. The CRO told me there was a supersonic (about 150kHz) oscillation at about 20dB (100 times) more power than was supposed to be going nto the headphones!

I never would have found it without a CRO.
 

abenn

Senior Member
You almost had me convinced, hippy :) But if I use < instead of > in the comparison the led should be off (no "ow") when the RC receiver is getting a signal, and it isn't. Let's see what debug tells me when I get round to trying it out.

kym, I don't see any option for "advanced" compiler on my "options" tab. I've just upgraded from 4.1.6 to 5.1.5, and I still can't see any way to run a simulation from anything other than a flowchart :confused:
 

MartinM57

Moderator
I haven't followed this thread in detail (I haven't got a clue about the subject matter) but

IF b13 > 3 ...and...
IF b13 < 3

...are not opposites.

The opposites are...
IF b13 > 3 ...and...
IF b13 <= 3
 

kym

Member
With the programming editor running
goto the view menu / options
once in the option menu press editor
Under compiler Press enhanced instead of original

The programming editor will now have a new menu called simulate
press run to simulate the program

Kym
 

abenn

Senior Member
I've upgraded to the latest version, 5.1.5, and "enhanced" is selected, but I still can't find a "simulate" menu :confused:
 

MartinM57

Moderator
I don't think it's there as standard - you have to do what Kym said, and make sure the compiler is set to "Advanced"...then it will appear on the top menu bar i.e. File|Edit|Simulate|PICAXE|View|Window|Help
 

abenn

Senior Member
After upgrading to 5.1.5 I've followed Kym's instructions, except that where he says "Under compiler Press enhanced instead of original" there is only a checkbox (from the use of the word "press" I infer, perhaps wrongly, there should be a pushbutton) for advanced. I've checked that -- it was checked by default anyway -- and clicked on "Apply", and still I don't have "Simulate" as a menu option when I've got a .bas file open :confused::mad:

I've tried reverting to "Original" and then back to "Advanced", with no luck. We are talking about "PICAXE Programming Editor Version 5.1.5 (Syntax DLL 131072)", aren't we? That's the info it gives when I click on "About".
 

Charliem

Senior Member
still I don't have "Simulate" as a menu option when I've got a .bas file open
There is a little yellow triangle beside the blue run button.When you want to start the simulation press the yellow button.Press it to stop.
 

hippy

Technical Support
Staff member
You need to go through the Programming Editor options, View -> Options -> Editor and you should see a display pop-up as attached ...
 

Attachments

Last edited:

abenn

Senior Member
Ahhh ... I've just clicked on "Colour Syntax" (it was on "Plain Text") and I've now got the "Simulate" menu.

Thanks, hippy.
 
Top