Welcome Anonymous
Fledgling
Fledgling
It is currently Mon Apr 19, 2021 7:01 am

All times are



Post new topic Reply to topic  [ Array ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Sat Feb 27, 2021 7:59 pm 
Offline
Emperor
Emperor
User avatar

Joined: Mon Jul 03, 2017 5:46 am
Posts: 1201
Location: Australia
buckshot164 wrote:
Not very many poeple are posting their code for fear of getting bashed for it. I am under attack now fror this. Sure takes the fun out of homebrewing when these attacks happen. Really you don`t need to program. You just need to know some values. I have been changing the code to make this process easier to do. Here is a sample.

*
'CODE
' PICAxe 20x2 Code for Sony that has a trail mode.
`With a jumper between b.7 and V you have feeder mode

`Edited by Charles Garrett and Floyd Newberry.
'=========
'11/25/10
'=========

'=========================
'Sony W290 3 wire
'=========================




#picaxe20x2
'#terminal 9600
#no_data
#no_table
disablebod

'=====================================================
' Map Ports
'=====================================================
'Symbol PT_IN = B.0 ' Photo Transistor input
'Symbol Spare_Out = C.1 ' Spare Mosfet
Symbol PT_Out = C.2 ' Photo Transistor output
Symbol Flash_Charge = C.3 ' Flash Charge Mosfet
Symbol Flash_Out = C.4 ' slave flash opto
Symbol CDS_Out = C.5 ' Output to LDR voltage Divider
'Symbol Battery_Monitor = B.6 ' ADC Input for battery monitor
'Symbol LDR_IN = B.5 ' LDR ADC Input
Symbol Shutter_Out = B.4 ' Shutter Mosfet
Symbol Power_Out = B.3 ' Power Mosfet
Symbol LED_Out = B.2 ' LED
'Symbol PIR_In = B.1 ' Input from PIR Circuit
Symbol Byte_Var = B1
Symbol ValidPIR = B2
Symbol PIR_Event = B3
Symbol WlkTestFlag = B4 ' Walk test status flag
Symbol WlkTestTime = B5 ' Number of 15 sec periods for walk test
Symbol CamPwrState = B6
Symbol CamPwrDownTimer = B7
Symbol Flash_Flag = B8' Flag to count the # of flashes seen
Symbol CDS_Value = B9
Symbol Night_Flag = B10
Symbol Day = B11
Symbol Night = B12
Symbol SlaveRefresh = B13
Symbol TimerLimit = B14
Symbol IsFlashCharged = B15
Symbol Power_On_Delay = W8
Symbol Slave_Charge_Time = W9
Symbol CamRefresh = W10
'Symbol To_Counter = W11
'Symbol PRELOAD = 63890 ' approx 15 sec at 31khz

'=====================================================
' Set Port Directions
'=====================================================
'Input PT_IN
'Output Spare_Out
Output PT_Out
Output Flash_Charge
Output Flash_Out
Output CDS_Out
'Output Battery_Monitor
'Input LDR_IN
Output Shutter_Out
Output Power_Out
Output LED_Out
'Input PIR_In
Input C.7
Input C.6
Input B.7
Input C.0

'=====================================================
'Camera Setup
'=====================================================

'Time to hold in the shutter button on camera in ms
Symbol Shutter_Time = 250

'Time Required to charge up slave in ms
'Set equal to 1 if a Slave Flash isn't used
Slave_Charge_Time = 10000

'time to hold in power button on camera in ms.
'Set equal to 1 if camera uses a switch instead of a momentary push button
Power_On_Delay = 250

'Delay after power on
symbol Shutter_pause = 1800

'Amount of time that can pass before the camera needs refreshed
'value=(10*timeinseconds/147)-1
'example if a 73.5s refresh is needed you would set it equal to 4
'4=(10*73.5/147)-1
Symbol CamRefreshLimit = 244

'Timervalue1 and Timervalue2 are in multiples of 5 sec
'Timer value to be used if B.0 is Low
Symbol Timervalue1 = 3

'Timer value to be used if B.0 is High
Symbol Timervalue2 = 6

'=====================================================
'Pullups
'=====================================================
'Disable all PUs
pullup %00000000

'=====================================================
' Configure ADC
'=====================================================
adcsetup = %010000000000 'make adc 10 an input
'============================================================================

' STARTUP
'============================================================================

; Allow board to stabilize for 20 sec
High LED_Out
pause 5000
GoSub CamPWR
pause 5000
GoSub CamPWR
pause 20000
Low LED_Out




Powerup:
WlkTestTime = 2 ' set walk test timer to 15sec intervals of timer
WlkTestFlag = 1 ' Turn on walk test mode
CamRefresh = 0
Night = 155; lux level 7 = 100k(R16) 2v @ 4v 2 X 256 / 4 = 128
Day = 144
Night_Flag = 0
SlaveRefresh = 0
CamPwrState = 0
IsFlashCharged = 0
' Do initial board setup for light & battery levels
GoSub CdsChk
IF Night_Flag = 1 And Slave_Charge_Time <> 1 Then GoSub Slave_Charge
'=====================================================
'Configure Interrupts
hintsetup %01100110 'set HINT2(PIR) & HINT1(FLASH) to trigger Interrupt at rising edge
Setintflags %00000100,%00000100 'enable interrupt flags


'=====================================================
Main: ' Main loop that checks for a PIR event, charges slave, turns off the cam if in trail mode and increments counters & timers, then sleeps for 15 secs and does it all over again:
'=====================================================
if Pinb.7 = 0 then 'Set TimerLimit to Number x 5 in seconds
TimerLimit = Timervalue1
else
TimerLimit = Timervalue2
endif

CamPwrDownTimer =0 'resets CamPWRDownTimer so timer can inc properly

If CamPwrState = 1 and pinC.7 = 1 then 'power cam down and wait 1 min (12x5s) if C.7 is jumpered
gosub CamPwr 'timer can be changed to use the timer limit settings for
do while CamPwrDownTimer <= 12 and pinC.7 = 1 'the other mode by changing the do while loop condition
'to TimerLimit instead of a number
pause 5000
inc CamPwrDownTimer
loop
endif

If CamPwrState = 1 then 'if cam is on starts the cam power down timer and checks for PIR event
Do While CamPwrDownTimer <= TimerLimit 'pauses for 5 sec x TimerLimit checking for a PIR event each time
If PIR_Event = 1 Then 'checks Pir for activity. Starts PirIntService and exits timing loop if found
Gosub PIR_IntService
exit
Endif
Pause 5000
Inc CamPwrDownTimer
Loop
Inc TimerLimit
If CamPwrDownTimer = TimerLimit then GoSub CamPwr 'turns cam off if timer finished counting
Else
If PIR_Event = 1 Then GoSub PIR_INTService
Endif

' Charge slave every 10 minutes if night_flag = 1 (40 15 second periods)
If SlaveRefresh = 40 And Night_Flag = 1 And Slave_Charge_Time <> 1 Then GoSub Slave_Charge

'reset slave refresh timer and mark slave flash as being uncharged
If SlaveRefresh = 40 And Night_Flag = 0 Then
SlaveRefresh = 0
IsFlashCharged = 0
EndIf

' Turn off walk test if time is up
If WlkTestFlag = 1 And WlkTestTime = 0 Then
WlkTestFlag = 0 'turn off walk test If Time is up
Byte_Var = 0 ' Flash LED to indicate walk test over
For Byte_Var = 0 To 7
pause 400
Toggle LED_Out
Next
Pause 3000 ' pause so CdsCHK does not see led and think it's day time
EndIf



' Increment counters & timers
If WlkTestFlag = 1 And WlkTestTime <> 0 Then Dec WlkTestTime : EndIf
If WLKTestFlag = 0 Then Inc CamRefresh : EndIf 'Camrefresh timer is passive using the time the processor is in its sleep cycle.
Inc SlaveRefresh


GoSub CdsChk
Sleep 7 'increases the time the processor sleeps by 2.1s:1 on x1 and x2 pics.
'Ex a value of 2 = 4.2s
'It is important to note that changing the sleep time will affect all passive timers
'used in the program. Use caution

If CamRefresh = CamRefreshLimit Then
CamRefresh = 0
GoSub CamPwr
Pause 5000
GoSub CamPwr
EndIf
GoTo Main


Interrupt:
'sertxd ("Interrupt ",13,10)
If hint2flag = 1 Then 'Check to see if INT2 has been triggered
PIR_Event = 1 'Set the PIR event flag
hint2flag = 0 'reset hint2flag to 0
EndIf

If hint1flag = 1 Then ' Flash has been detected
'sertxd ("Flash Flags ", #Flash_Flag,13,10)
Inc Flash_Flag
hint1flag = 0
Setintflags %00000010,%00000010 'enable interrupt flags FOR FLASH ONLY!
EndIf


hintflag = 0

Return


PIR_INTService:

PIR_Event = 0
; +++++++ Now See how long the port is high ++++++++++++++
Byte_Var = 0 'clear the counter
Do While Pinb.1= 1 'While the PIR is high (motion detected)
Inc Byte_Var 'Inc our counter
'Pause 1 'un-comment for a longer period
If Byte_Var >= 2 Then
ValidPIR = 1 'flag the motion detected as valid
Exit
EndIf
Loop



If ValidPIR = 1 Then 'If valid motion then
ValidPIR = 0

' WalkTest
If WlkTestFlag = 1 Then 'if walktest then turn on led to indicate PIR event
WlkTestTime = 2 'reset walktest timer back to original count again
Byte_Var = 0
For Byte_Var = 0 To 19
Toggle LED_Out
Pause 20
Next
Pause 4000; wait a few secs to settle PIR
GoTo PIR_INTService_Exit
EndIf


If Night_Flag = 1 And Slave_Charge_Time <> 1 Then
High PT_Out ' Turn on PT to detect flash
Setintflags %00000010,%00000010 'enable interrupt flags FOR FLASH ONLY!
If IsFlashCharged = 0 Then GoSub Slave_Charge 'if flash isn't charged recharge it
EndIf

Flash_Flag = 0


If WlkTestFlag = 0 Then
If CamPWRState = 0 then GoSub CamPWR ' Turn the camera on for the first time
Pause Shutter_pause
If night_flag =1 And Slave_Charge_Time <> 1 then
GoSub Fire_Flash
Else
Gosub Shutter
EndIf


EndIf

Endif

PIR_INTService_Exit:
'sertxd ("PIR Exit ",13,10)
Setintflags %00000100,%00000100
ValidPIR = 0
Return

LED_Blink:
'Byte_Var = 0
For Byte_Var = 0 To 19
Toggle LED_Out
Pause 20

Next
Return

Flash_Led:
For Byte_Var = 1 To 50
Toggle LED_Out
pause 20
Next
Return

CamPWR:
CamPwrState = CamPwrState ^ 1 'Toggles CamPwrState Var
if campwrstate = 1 then 'stuff to do when cam is turned on

If Power_On_Delay = 1 then High Power_Out : Endif

Endif
If Power_On_Delay <> 1 Then
High Power_Out
pause Power_On_Delay
Low Power_Out
EndIf
if CamPwrState = 0 then 'stuff to do when cam is turned off

If Power_On_Delay = 1 then Low Power_Out : Endif
Endif
Return

Shutter:
High Shutter_Out
pause Shutter_Time
Low Shutter_Out
Return

Fire_Flash:
'setfreq m32
'pause 8
Flash_Flag = 0 'only here for instances where a bright light may have messed up the counter. IE Lightning or a flashlight
'sertxd ("Flash Start ",13,10)
timer = 0
settimer 65505 'aprox 1ms at 8mhz
'settimer 65411 'aprox 1ms at 32mhz
High Shutter_Out

Do While flash_flag != 2
If timer = Shutter_Time Then
'Inc TO_Counter
'If TO_Counter =1000 Then
Flash_Flag = 0 ' Reset flags
'TO_Counter = 0
GoSub Flash_Led ' Flash Led to indicate time out.
GoTo Flash_Exit
EndIf
Loop
'pause 10 'used to help sync camera and flash
' FireFlash
High Flash_Out
pause Shutter_Time
Low Flash_Out
Flash_Exit:
Low Shutter_Out
Flash_Flag = 0 ' Reset flags
'TO_Counter = 0
Low PT_Out
settimer off
'setfreq m8
'pause 2
gosub Slave_Charge

Return

CdsChk:
High CDS_Out 'Turn on pin to supply voltage to cds voltage divider
readadc 10 , CDS_Value ' Read light value
'sertxd ("CDS Value ",#CDS_Value,13,10)
'IF Night_Flag IS SET THEN WE CHECK TO SEE IF THE LIGHT LEVEL IS > = 144 IF ADC GREATER OR = THEN STILL DARK AND EXIT
'IF ITS BELOW 144 THEN WE CLEAR NIGHT_FLG AND RETURN
'IF Night_Flag = 0 THEN CHECK TO SEE IF ADC ABOVE 155 THEN WE SET NIGHT_FLG AND RETURN
Low CDS_Out 'Turn off voltage divider
If Night_Flag = 1 And CDS_Value >= Day Then
GoTo CdsChk_Exit 'already set and Still dark so we exit
Else
Night_Flag = 0 ' already set and Daylight so clear flag
EndIf
If Night_Flag = 0 And CDS_Value >= Night Then
Night_Flag = 1 ' Its dark so set flag
If IsFlashCharged = 0 And Slave_Charge_Time <> 1 Then GoSub Slave_Charge ' Charge the slave up also if it needs it.
Else
Night_Flag = 0 ' Daylight so clear flag
EndIf
CdsChk_Exit:

Return

Slave_Charge:
High Flash_Charge
Pause Slave_Charge_Time ' pause to allow cap to charge up
Low Flash_Charge
SlaveRefresh = 0 ' restart our slave refresh timer.
IsFlashCharged = 1
Return


That may as well be written in Chinese or something as it means absolutely nothing to us lol :rofll

_________________
www.trevorwillistaxidermy.com
Vimeo: Trevor Willis


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 28, 2021 10:19 am 
Offline
Emperor
Emperor
User avatar

Joined: Wed Oct 20, 2010 7:40 am
Posts: 2535
I don't understand it either Trevor, well not yet anyhow, but I hear what you're saying.

From what I have been told is that once you buy a pic-axe starter kit (it's the top board and the battery holder in the top of the pic) or build your own programmer board. That programming your own control board is quite easy. Basically, it consists of a pic-axe programming board, power supply and you will need to download a pic-axe program to get started. Maybe somebody can explain this better but that's my general understanding of it.


You do not have the required permissions to view the files attached to this post.

_________________
To greater appreciate an animal is to walk in its footsteps


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 14, 2021 5:16 pm 
Offline
Emperor
Emperor
User avatar

Joined: Wed Aug 04, 2010 2:37 pm
Posts: 785
Location: Decherd, Tennessee
Someone should redo the AIO board using the M2 chips....so much easier to program and understand the programming.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ Array ]  Go to page Previous  1, 2, 3

All times are


Who is online


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group