How to clear w1 and w2

212

Senior Member
I'm trying to flash an LED in sync with a digital camera flash.
(working on an RF remote slave flash)

I think I'm close because I can see the LED lit in the picture. But...if the sensor I'm using misses the pre-flash from the camera, it does not blink the LED that time, and next time it is out of sync.

Maybe I need to clear w1 and w2??? ... OK...how do you do that??? Or am I barking up the wrong tree altogether? Oh yeah, if you can't tell....I'm "basically" illiterate still...please help!

main:

count 3, 1, w1
if w1 = 1 then blink
goto main

blink:

pause 125
count 3, 1, w2
if w2 = 1 then flash


flash:

high 1
pause 20
low 1
pause 1000
goto main
 

westaust55

Moderator
I do not believe that you need to clear the w1 and w2 variables.
The COUNT command will/should do that automatically.

Code:
main:

count 3, 1, w1 
if w1 = 1 then blink
goto main
This section is looking for a signal/pulse on input 3 over a 1 second period.
If no pulse detected, then, it loops around and tries again.
If a pulse occurs when the program is not in the COUNT command monitoring period then it is missed.

Also if the input has any contact bounce (depends on the type of sensor you have) then you might get more than 1 pulse and so skips and tries again.
If the sensor involves a relay or switch contact then try using:
IF w1 > 0 THEN blink


Code:
blink:

pause 125
count 3, 1, w2
if w2 = 1 then flash
[COLOR="Red"]; you need to add an extra command here - see text below[/COLOR]

flash:

high 1 
pause 20
low 1 
pause 1000
goto main
This part of the program is again looking for a second pulse and if found goes to the flash routine
BUT . . . if no pulse was detected, it still drops through to the flash routine.
You need a GOTO Main or GOTO blink before the flash: label
 

212

Senior Member
OK, thanks, that makes since. But it leads me to another question then. Is it possible to keep looking for the second flash, continuously, for a whole second or so before going back to main? And it needs to go right to flash if it does see it, not wait the rest of the second.

Oh, I have a photo-diode looking for the flash right now, but will have a photo-transistor in it's place when I get one.
 
Last edited:

Dippy

Moderator
Of course it's possible. But only if the pre-flash is detected. Otherwise the code won't know where it is...

BUT, all this pre-supposes you have your sensing correct.
With a photodiode and photo transistor any significant ambient light will cause an apparent 'high' (1) at the input pin.

You haven't included your circuit schematic, or described how the photodiode/transistor views the flash.
Have you just copied that one you posted on your other thread which used the 12F chip?
If so your code won't work.

Do you think this thread should be merged with your other one. Whilst it started off with a different question it's heading in the same direction already.... :)

PS. Time to get a 'scope I think. Without one, you just will NOT know what's coming out of your sensor circuit and you'll waste your time unless you strike lucky.
 

212

Senior Member
Yep it is heading that way I guess. I did not mean for it to though. I thought my question here was different enough to warrant another topic, so people searching for similar questions might come across this one and find what they need. No, I am not using the circuit from the other thread, you are right, it will not work with this code I made up. I'll draw what I have and post it on the other topic :)

Back to my original question though, if I may. The example code in manual 2...looking at count...shows counting pulses on a pin for 5 seconds, then display the results. I think I changed it where it counts for 1/1000 of a second to make it quick. If the results of the counting is 1, then I want to go to the next sub...which I just called blink for no real reason. I had to put the pause 125 to keep the LED from lighting as soon as it got to blink.

I just recently got serin to do something useful for me, and I learned about serin hang. I probably assumed wrong that there might be a count hang too I guess. Not real sure what I was thinking, I spend a lot of time in the sun you know lol...

After all that nonsense, please can someone answer my origonal question....what becomes of w1 and w2 up there??? Are they overwritten when the count command is used again? Or...do I need to clear the count first???
 

hippy

Ex-Staff (retired)
To answer the clearing w0 and w2 question, the COUNT command ( also PULSIN and other input commands ) will overwrite the variable so no need to clear them first.

COUNT probably isn't the best way to do what you want, but could possibly work ( perhaps most times if not always ). What you really need to do is look for the pre-trigger flash, wait for that to go away then wait for the full flash. In pseudo code ...

Code:
WaitForPreFlash:
  If no flash Goto WaitForPreFlash
WaitForPreFlashToFinish:
  If flash Goto WaitForPreFlashToFinish

HadPreFlash:
  timer = howeverLong

WaitForMainFlash:
  If Flash Goto GotMainFlash
  timer = timer - 1
  If timer = 0 Goto WaitForPreFlash ' Timedout
  Goto WaitForMainFlash

GotMainFlash:
  Turn LED On
WaitForMainFlashTo Finish:
  If flash Goto WaitForMainFlashToFinish
  Turn LED Off
  Goto WaitForPreFlash
 

212

Senior Member
Thank you :)

westaust55, thank you too! That was very helpful! The "will/should do that automatically." still left me wondering a little. I do try doing stuff myself before I ask, but when something does not work I try looking for a misunderstanding I may have had before I go on and on getting the same results.

Hey...I really appreciate you guys helping me!
 

Dippy

Moderator
212:
Also have a look at Do...Loop.
The structure may help and it makes your code very readable.

But, to my poor little mind, you've got to ensure your detection works.
If you can't detect a pre-flash then your device will be waiting all day for the main event.
Invest a little time in reliable sensing.

Assuming PICAXE is fast enough and that your sensing is good enough then 3 x Do..Loop Untils will do the job.

But I don't know how good your electronics is.
 

212

Senior Member
Feel free to merge this with the similar one about the RF slave trigger if you want to.

Yep, I do need to work on the electronics part too, one depends on the other I guess. I know I'm way over my head, but no guts no glory :) I need to do some more homework, then I'll be more ready to implement the ideas I'm getting.

I know...get a scope...OK :)
 
Top