Jump to content
Lv2Hunt

Anyone Want To Help With Picaxe Problem?

Recommended Posts

below is a code I have written for my new control board. However I am having trouble with the timers. The Main section of the code is a big loop that checks for motion, checks pir every 10 minutes, refreshes camera every hour at night, charges slave every 10-15 minutes at night. The problem is that the timers are not even close to the actual time I want.

for example: the check pir timer is actually around 1 1/2 minutes. I thought I had it right but I guess not.

 

How do I know what the actaul time is going to be?

 

 

 

#REM

 

CANON A620

 

WHITETAIL WHITTLE

SHARP SHOOTER WITH SLAVE

PICAXE 18M2 CHIP

 

1 MINUTE DELAY WITH SWITCH 1 (B.1) OFF

3 MINUTE DELAY WITH SWITCH 1 (B.1) ON

2 FLASH CAMERAS WITH SWITCH 2 (B.0) OFF

3 FLASH CAMERAS WITH SWITCH 2 (B.0) ON

 

#ENDREM

 

DISABLEBOD

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

'18M2 Pin Out

 

'B.0 switch

'B.1 switch

'B.2 unused

'B.3 unused

'B.4 spare opto

'B.5 camera shutter

'B.6 camera power

'B.7 led

'C.0 slave mosfet

'C.1 slave opto

'C.2 CDS "read light"

'C.3 CDS power

'C.4 program

'C.5 PIR

'C.6 PT (in)

'C.7 PT (out)

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

'NAMING PINS

 

symbol Flash_count_switch = PinB.0

symbol delay_switch = PinB.1

symbol unused1 = B.2

symbol unused2 = B.3

symbol spare_opto = B.4

symbol shutter = B.5

symbol campwr = B.6

symbol led = B.7

symbol slave_charge = C.0

symbol trigger_slave = C.1

symbol cds_read = PinC.2

symbol cds_power = C.3

symbol program = pinC.4

symbol pir = PinC.5

symbol PT_IN = pinC.6

symbol PT_OUT = C.7

 

'NAMING VARIABLES

 

symbol Walktest_Timer = w6 'walktest timer

symbol PTTimer = w7 'PT timer

symbol SlaveRefreshTimer = w8 'Slave refresh timer

symbol SlaveRefreshTime = w9 'how long until slave refreshes

symbol CameraRefreshTimer = w10 'camera refresh timer

symbol CameraRefreshTime = w11 'how long until camera refreshes

symbol CdsCheckTimer = w12 'Cds timer

symbol CdsCheckTime = w13 'how long until cds needs to be checked

 

symbol CDS_Value = b0 'reading from cds

symbol Day_Night_Value = b1 'a set value that determines day or night

symbol Arm_Blinks = b2 'loop to blink led to show walktest complete

 

symbol Night_Flag = bit0 'keeps track of night or day

symbol SlaveOn = bit1 'keeps track of slave ON or OFF

symbol CameraOn = bit2 'keeps track of camera ON or OFF

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

'SETTING VARIABLES

 

Day_Night_Value = 144 'adjust this number for CDS value

Night_Flag = 0 'set Night_Flag

SlaveOn = 0 'set SlaveOn

CameraOn = 0 'set CameraOn

CameraRefreshTime = 50000 'THIS NUMBER CHANGES HOW LONG UNTIL THE CAMERA REFRESHES (AT NIGHT)(APPROX EVERY 60 MINUTES AT 50000)

SlaveRefreshTime = 8336 'THIS NUMBER CHANGES HOW LONG UNTIL THE SLAVE REFRESHES (AT NIGHT) (APPROX EVERY 10 MINUTES AT 8336)

CdsCheckTime = 8336 'THIS NUMBER CHANGES HOW LONG UNTIL THE CDS IS CHECKED (APPROX EVERY 10 MINUTES AT 8336)

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

'SETTING INPUTS/OUTPUTS

 

input b.0

input b.1

output unused1

output unused2

output spare_opto

output shutter

output campwr

output led

output slave_charge

output trigger_slave

input c.2

output cds_power

input c.5

input c.6

output PT_OUT

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

Camera_Test:

 

high led 'power on led

high slave_charge 'turn on slave

sleep 2 'pause 4 seconds

gosub CamOn 'power camera on

sleep 3 'turn cam on for 6 seconds

gosub CamOff 'power camera off

low slave_charge 'turn off slave

low led 'power off led

pause 500 'pause 500 ms

goto Walk_test 'move to walk test

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

Walk_test:

 

Walktest_Timer = 300 '300 for 30 second walk test

Do While Walktest_Timer > 0

If Pir = 1 then 'if pir detects motion then

high led 'power on led

pause 1000 'keep led on for a 1 second

low led 'power off led

Walktest_Timer = 300 'reset timer if walk test is interrupted

sleep 1 'pause for approx 2.1 sec for pir to settle

endif

Walktest_Timer = Walktest_Timer - 1 'decrease W0 timer by 1

pause 100 'pause 100 ms

loop

for Arm_Blinks = 1 to 4 'loop for 4 times to flash led to show walk test complete

high led 'power on red led

pause 500 'pause 1/2 second

low led 'turn off led

pause 500 'pause 1/2 second

next Arm_Blinks

sleep 1 'pause for approx 2.1 sec

 

gosub CdsChk 'inital cds check

gosub main

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

Main: 'LOOP THAT CHECKS FOR MOTION, CHECKS CDS, REFRESHES CAMERA, AND REFRESHES SLAVE

 

If pir = 1 then 'if motion is sensed

gosub Cam_Functions 'go to take picture

endif

 

Inc CdsCheckTimer 'add 1 to CDS check timer

if CdsCheckTimer >= CdsCheckTime then 'if cds check time is reached

gosub CdsChk 'check cds

CdsCheckTimer = 0 'reset timer

endif

 

if Night_Flag = 1 then 'IF NIGHT

Inc CameraRefreshTimer 'add 1 to camera refresh timer

Inc SlaveRefreshTimer 'add 1 to slave refresh timer

 

if CameraRefreshTimer >= CameraRefreshTime then 'if camera refresh timer is reached then

gosub Camera_Refresh 'refresh camera

CameraRefreshTimer = 0 'reset timer

endif

 

if SlaveRefreshTimer >= SlaveRefreshTime then 'if slave refresh timer is reached then

gosub Slave_Refresh 'refresh slave

SlaveRefreshTimer = 0 'reset timer

endif

endif

 

if Night_Flag = 0 then 'IF DAY

CameraRefreshTimer = 0 'reset timer

SlaveRefreshTimer = 0 'reset timer

endif

 

goto Main

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

Cam_Functions:

 

gosub CdsChk 'check for day or night

 

'XXXXXXXXXXX NIGHT FUNCTIONS XXXXXXXXXXX

 

If Night_Flag = 1 Then 'if NIGHT then

 

if SlaveOn = 0 then 'if flash is not on at night turn it and PT on

high PT_OUT 'turn on PT

high slave_charge 'turn on slave

SlaveOn = 1 'slave is on

SlaveRefreshTimer = 0 'reset timer

endif

 

if CameraOn = 0 then 'if camera is off turn it on

gosub CamOn 'power on camera

endif

pause 2500 'pause between power and shutter

gosub NightPicture 'shutter picture with slave

sleep 2 'pause after pic taken to save to card (approx 4 seconds)

gosub CamOff 'power off camera

sleep 5 'pause 10 more seconds for slave to charge

 

low PT_OUT 'turn off PT

low slave_charge 'turn off slave

SlaveOn = 0 'slave is off

SlaveRefreshTimer = 0 'reset timer

CameraRefreshTimer = 0 'reset timer

endif

 

'XXXXXXXXXXX DAY FUNCTIONS XXXXXXXXXXXX

 

if Night_Flag = 0 Then 'if DAY then

 

if CameraOn = 0 then 'if camera is off turn it on

gosub CamOn 'power on camera

endif

pause 2500 'pause between power and shutter

gosub ShutterPic 'shutter picture

sleep 2 'pause after pic taken to save to card (approx 4 seconds)

gosub CamOff 'power off camera

CameraRefreshTimer = 0 'reset timer

endif

 

'XXXXXXXXXXX DELAY TIMES XXXXXXXXXXXXXX

 

if delay_switch = 1 then

sleep 28 '1min delay approx. (28 x 2.1 = 58.8 secs)

else

sleep 84 '3 minute delay approx.

endif

 

goto Main 'do it all over again

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

ShutterPic:

 

high shutter

pause 300 'pause 300 ms

low shutter

return

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

CamOn:

 

high campwr

pause 300 'pause 300ms

low campwr

CameraOn = 1

 

return

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

CamOff:

 

high campwr

pause 300 'pause 300ms

low campwr

CameraOn = 0

 

return

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

Camera_Refresh:

 

high campwr 'turn on camera

pause 300

low campwr

sleep 3 'pause for approx. 6.3 seconds for camera to refresh

high campwr 'turn off camera

pause 300

low campwr

pause 300

 

CameraRefreshTimer = 0

CameraOn = 0

 

Return

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

Slave_Refresh:

 

high slave_charge 'turn on slave

sleep 5 'pause for approx. 10 seconds for slave to charge

low slave_charge 'turn off slave

pause 300

 

SlaveRefreshTimer = 0

SlaveOn = 0

 

Return

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

NightPicture:

 

setfreq m32

high Shutter ' Press Shutter Button to start the picture taking process

PTTimer = 0

 

if Flash_count_switch = 0 then ' skip ahead a flash if a two flash camera

goto twoflash

endif

 

do while PT_IN = 1 and PTTimer < 10000 ' wait for first flash

PTTimer = PTTimer + 1

loop

 

if PTTimer < 10000 then

PTTimer = 0

endif

 

do while PT_IN = 0 and PTTimer < 10000 ' wait for first flash to end

PTTimer = PTTimer + 1

loop

 

if PTTimer < 10000 then

PTTimer = 0

endif

 

twoflash:

 

do while PT_IN = 1 and PTTimer < 10000 ' wait for second flash

PTTimer = PTTimer + 1

loop

 

if PTTimer < 10000 then

PTTimer = 0

endif

 

do while PT_IN = 0 and PTTimer < 10000 ' wait for second flash to end

PTTimer = PTTimer + 1

loop

 

if PTTimer < 10000 then

PTTimer = 0

endif

 

do while PT_IN = 1 and PTTimer < 10000 ' wait for Third flash

PTTimer = PTTimer + 1

loop

 

if PTTimer < 10000 then ' do not trigger flash if we have timed out

high trigger_slave

pause 200

low trigger_slave

endif

 

low Shutter

setfreq m4

return

 

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

CdsChk:

 

High cds_power 'Turn on pin to supply voltage to cds voltage divider

readadc c.2, CDS_Value 'Read light value

Low cds_power 'Turn off voltage divider

 

If CDS_Value <= Day_Night_Value Then

Night_Flag = 1 'Night

endif

 

If CDS_Value > Day_Night_Value Then

Night_Flag = 0 'Day

endif

 

Return

 

Share this post


Link to post
Share on other sites
 

I don't see a sleep or nap or pause in the main loop? What is the 8336 value? Ar you basing the loop on the frequency that the chip is running at?

Share this post


Link to post
Share on other sites
 

Yes I am basing the loop on what freq the chip runs off.

That's what I am asking how do I set it up to get the right values for my timers??

What's the easiest way to make this work?

Share this post


Link to post
Share on other sites
 

You need to use Nap 3, pause 10, or sleep 1 inside main: loop to keep time, otherwise it will run way fast, you will have to play with values to get your time right on. Try Nap 3 or 4 and write code to light up led and set timing from that

Share this post


Link to post
Share on other sites
 

I see ghoot chimed in, he should get you all set I never based timers off of chip frequency, I missed that in code been up all night 3rd shifter.

Share this post


Link to post
Share on other sites
 

Ok I see what your saying. I have to add pauses to slow the loop down or it will run too fast.

If I do that then my pir wolnt sense motion frequently like it should?

I will have to put the pir on an interrupt then?

Share this post


Link to post
Share on other sites
 

I nearly always use Interrupt to detect PIR trips, I set a Flag that the PIR tripped and if it's TRUE (during a timer loop) reset the timer. I don't have my PicAxe codes on this PC or I would post a snippet of the Loop but I think you'll get it.

 

be sure to carefully read the properties of Nap, pause, and sleep, there are differences

Edited by Tinhorn

Share this post


Link to post
Share on other sites
 

Naw, if you use a Nap3 you'll be OK. That's what I use on the SSII. I would personally stay away from the interrupt. It can get really KORNfusing using interrupts and having to disable them each time you go refresh the flash or the camera and then enable them again after it's done.

 

EDIT: Oops, I posted this before seeing Tinhorns post. I'm not arguing with him, cuz he is The MAC Daddy, but personally, I don't like the interupts. I use them on the LCD board for the button presses and the PIR, so it's confusing. May not be too bad using them just for the PIR.

Edited by ghoot

Share this post


Link to post
Share on other sites
 
 
Ok I see what your saying. I have to add pauses to slow the loop down or it will run too fast.

If I do that then my pir wolnt sense motion frequently like it should?

I will have to put the pir on an interrupt then?

 

 

nap 3 is 144 miliseconds and 4 is 288

 

interrupt is an option but you will have to disable while cam is being refreshed or it may try to turn on cam when it is already on hence turning it off

 

Try without interrupt to see what you get,

Share this post


Link to post
Share on other sites
 

If you are in the middle of say refreshing the camera and motion is detected, then the interrupt will send you to your interrupt code, but the camera is already on because it was being refreshed. now your code to turn it on will turn it off because the cam is out of sequence with the code.

 

EDIT: Posted before seeing mheimburg1's post too, but yeah, what he said. :P

Edited by ghoot

Share this post


Link to post
Share on other sites
 

sorry i havent responded hagshouse has a tendency lately of kicking me out for a day or two and wolnt let me post anything.

 

so what your saying is that if i put a nap 3 anywhere in my main: loop that is should get:

25,000 = 1hour 50,000 = 2hours

or somewhere in that ballpark?

just like the ss2 code?

Share this post


Link to post
Share on other sites
 
 

We'll i have timings correct now but I just can't seem to get main loop working correctly??? For the last week I have tried every arrangement of code I know but I can't seem to get it.

 

I have tried interrupts

Do until

If pir = 1

But I get weird operation with each one

 

Anyone have ideas?

Share this post


Link to post
Share on other sites
 
 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×