Another chance

212

Senior Member
I got a Picaxe VCR controller working a while back, with help from you guys...thanks! What this does is, tell my VCR to record when I'm receiving a signal from one of my RF video cams. When I first built it, I had stereo sound channels, so I use one of them to send a tone to the receiver, which was picked up by a 567 encoder...or is it as a decoder??? Anyway, the 567 puts a pin low when it hears the correct tone. I used the low pin to trigger a Picaxe 08M to control the buttons on a universal remote...worked great!

OK, so now I'm using the controller with a radio that has only one audio channel, and I have to have sound you know :) Soooo...I changed the 567 circuit to listen for the video signal coming in...and it worked pretty good.

Now....someone went and built a tower nearby, and there is something coming off that thing that messes with my RF. The audio signal had no problem getting through, but the video will ....ummmm....blink a little???
To keep the recording going when MY RF is active, I need some sort of a "filter" ???

Now I have been working on this "filter" and have close to what I want, or need. As you can see I check pin3 every tenth second, and if it is high, from interference, I count how many times it happens. After 10 times, I give it just one more chance before stopping the recorder.

The problem is this....and why I can't see it is beyond me...if everything is OK after the b2 only reaches...maybe 8 times of not being OK, it needs to reset b2 to zero again. In other words, the way it is now, even a minute or two later, it still has the demerits against it from the start. Any ideas on how to do it the right way???

Code:
recording:

 do while b2 < 10
 pause 100
 if pin3 = 1 then
 b2 = b2 + 1
 endif
 loop
 b2 = 0
 goto make_sure
 

make_sure:

 pause 100
 if pin3 = 1 then quit
 if pin3 = 0 then recording
 
Last edited:

212

Senior Member
I came up with this so far, but it just looks goofy lol... If you need me, I'll be working on Picaxe code :)


Code:
recording:

 do while b3 < 20
 if pin3 = 1 then
 b2 = b2 + 1
 endif
 if b2 = 10 then make_sure
 b3 = b3 + 1
 pause 100
 if b3 = 20 and b2 < 10 then
 b2 = 0
 endif
 loop
 b3 = 0
 goto recording
 

make_sure:


 b2 = 0
 b3 = 0
 pause 100
 if pin3 = 1 then quit
 if pin3 = 0 then recording
 

inglewoodpete

Senior Member
212: Without adequate comments against your code, no one will have a clue what's supposed to happen. In a week's time, you will be struggle to know what it was supposed to do either.

Peter
 

212

Senior Member
I just did it and I have to struggle to know what it is supposed to do too. I do comment the codes I save, but when I try to post code on here, with comments, it gets all jumbled and you can't read it anyway??? Also, only on this forum, I'll be typing along, only to look up and see all kinds of things that just appeared out of nowhere. It just did it while I was typing that sentence??? It would make more since.....(internet options just popped up just now).....if I posted the whole code with the comments, but I would have to put it in a regular reply...no code box. I think that is frowned upon, so I only post little pieces most of the time.

Anyway, what this does for me now is, go ahead and keep recording if I get little short blips in the signal. The way it was before changing it, it would stop recording right away whenever a signal was lost, even if only for a fraction of a second. I have been running it like this for several hours now, and it is working perfect so far. If it continues to do so, I'll put my comments in and call it good enough for now.

Anyone else have problems posting code with comments....or is it just me???:confused:
 
Last edited:

westaust55

Moderator
Never had any problems posting code as such. Nothing becomes totally unreadable if its just a comment following after an apostrophe or semicolon.

Sometimes the formatting in terms of spaces (that's actual spaces and not tabs) is not ideal but far better than with straight post into the body of the post or using. I might go back into the post to do some "tweaks" to the number of spaces so the presentation looks better and vertical lines align better.

Have a look at code I included in posts such as here:
http://www.picaxeforum.co.uk/showthread.php?t=10014&page=3
 
Last edited:

212

Senior Member
That figures.....seems everything always happens to me and nobody else...

I' ll see if I can fix the comments in there tomorrow, just in case anyone finds this thread later on.
 

boriz

Senior Member
Not entirely convinced I’ve understood correctly, but here goes…

Code:
do
	'..stuff..
	'..stuff..
	if pin3=1 then gosub check_signal
loop

check_signal:
for b2=1 to 100
	pause 10
	if pin3=0 then exit
next b2
if b2>100 then stop_recording
return
During the main loop, when the signal is interrupted (pin3 goes high), a test count begins checking the pin at 10mS intervals. If the signal returns anytime within one second, the test count immediately exit’s and the main loop continues. If the signal does not return within one second, the recording stops. Is that it?
 

212

Senior Member
boriz, you must be a genus to have made since of what I said there...but you nailed it! While I was at work today, my VCR recorded probably 7~8 very short videos. That tells me my code did not fix the problem, because they should be a minimum of three minutes each....that's how long I have the camera and transmitter on with an event. Your version looks much better, thanks, I'll give that a try...
I'm going to see if my code turns out readable, if it does, I'll edit in your suggestion. It will go where I have "recording:"

EDIT: I'll try this for a bit... and if it works, I'll do a dance...thanks!

Code:
symbol counter = b1

 low 0  'led output off
 low 1  'record button relay off
 low 2  'stop button relay off
 low 4  'power button relay

main:

 if pin3 = 0 then recheck  'if input 3 is low, check again
 if pin3 = 1 then goto main  'if input is high, do a loop

recheck:      'checking to be sure a real trigger happened

 high 0     'turn on yellow LED
 pause 300     'pause 3/10 second
 low 0      'turn off yellow LED     
 if pin3 = 0 then record   'if pin 3 is still then record video
 if pin3 = 1 then goto main  'if it was a false, then return and wait for event    
     

record:

 high 0     'turn on yellow LED
 high 4     'turn on power button relay...if used
 pause 300     'wait 3/10 second
 low 4      'turn off power button relay
 pause 300     'wait 3/10 second
 high 1     'turn on record relay
 pause 300     'wait 3/10 second
 low 1      'turn off record relay       
 pause 300     'wait 3/10 second
 high 1     'turn on record relay again....for universal remote to work with this 
 pause 300     'wait 3/10 second
 low 1      'turn off record relay
 pause 5000     'wait 5 second
 goto recording


recording:

 do
 if pin3=1 then gosub check_signal
 loop       'recording till video signal is missing


check_signal:	'this will check for video signal every 10ms for up to a second

 for b2=1 to 100
 pause 10
 if pin3=0 then exit	'if signal returns then go back to recording
 next b2
 if b2>100 then make_sure
 return

 

make_sure:	'one last chance before stopping VCR

 pause 100
 if pin3 = 1 then quit
 if pin3 = 0 then recording

 
quit:

 low 0      'turn off yellow LED
 high 2     'turn on stop relay
 pause 1000  'wait 1 second
 low 2      'turn off stop relay
 

for counter = 1 to 5    'blink yellow LED to show a time delay for VCR to stop and turn off

 high 0     'turn on yellow LED
 pause 500     'wait 5/10 second
 low 0      'turn off yellow LED
 pause 500     'wait 5/10 second

 next counter    'this will blink yellow LED 5 times while waiting 5 seconds
 
 high 0	'turn on yellow LED
 high 4     'turn on power relay
 pause 1000 'wait 1 second
 low 4	'turn off power relay
 low 0	'turn off yellow LED
 pause 1000	'wait 1 second
 goto main   'now we wait for another event
 
Last edited:

boriz

Senior Member
You are messing up the return stack and the loop stack. Your program is doing something like this:

Code:
Main:
Gosub Main
(Never gets to the RETURN command)
And something like this:

Code:
Main:
Do
	Goto main
Loop
(Never gets to the LOOP command)
Also, there is no need for the Make_Sure section. If a signal absence of 1 second is not sufficient, just increase it to two seconds. EG:

Code:
for b2=1 to 200 &#8216;<<<  200*10mS = 2 sec.
      pause 10
      if pin3=0 then exit	'if signal returns then go back to recording
next b2
if b2>200 then stop_recording &#8216;<<< same 200 here.
return
I would also suggest that you use the same method for starting the recording. But with a shorter test loop. EG:
Code:
for b2=1 to 50 &#8216;<<<  50*10mS = 0.5 sec.
      pause 10
      if pin3=1 then exit	'signal has dropped, don&#8217;t record
next b2
if b2>50 then start_recording &#8216;<<< same 50 here.
Return
Both could be put together inside one loop:

Code:
symbol recording=b0
do
	if pin3=1 and recording=1 then
		;;;;Here we are currently recording, but the signal has dropped.
		;;;;Check for signal return within two seconds, otherwise stop recording.
		for b2=1 to 200
			pause 10
			if pin3=0 then exit
		next b2
		if b2>200 then gosub stop_recording			
	elseif pin3=0 and recording=0 then
		;;;;Here we are not recording, but a signal has been detected.
		;;;;Check for signal loss within half a second, otherwise start recording.
		for b2=1 to 50
			pause 10
			if pin3=1 then exit
		next b2
		if b2>50 then gosub start_recording
	endif
loop

start_recording:
recording=1
'..stuff..
return

stop_recording:
recording=0
'..stuff..
return
The additional variable &#8216;recording&#8217; is needed so that the program knows which test to perform.
 

212

Senior Member
First thing first...it has been working flawlessly all night last and all day today...THANKS...you should have seen the dance I did :eek:

That was almost the first thing I wrote when I got my Picaxe. In fact, that was the main reason I wanted one. I did get a controller working before this, but with the universal remotes needing the record button pushed two times to start the VCR recording, the Picaxe made it a LOT easier. I have learned some new things since then, mostly from you guys helping, so I can do some re-writing now. But I don't quite follow everything you said boriz. I will change the main, and the "re-check" and nope, I don't need the "Make_Sure" , but I need to learn more about the other things...I don't want to do it just because you gave me the answer.

I'm going to go back and read some in the manuals again. The first time around I had no idea what most of it was even talking about. I need to figure out what you mean by "You are messing up the return stack and the loop stack."...it looks like it works right in the simulator??? Don't answer that....Let me go see if I can figure it out, change some things around, then I'll run it by you again.
 
Top