This was giving me a bit of a problem to code even though it seemed rather simple. I eventually broke down and flow charted it to help me out.
When sound is detected it will signal the video camera to record for 20 seconds before checking for sound again. If sound is detected then it will
wait another 20 seconds before checking again. If sound is not detected it signals the camera to stop recording.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
led = 16 'IR led
'ADC circuit on pins 21 22
bits = 12
fbpin = 21
adcpin = 22
VAR
long volume
OBJ
vp : "Conduit" 'for viewport
magicir : "magicir_010"
Pub Main
cognew(@asm_entry, @volume) 'runs simple ADC code taken from code library
vp.config(string("start:dso"))
vp.config(string("var:volume"))
vp.share(@volume,@volume)
dira[led]~~
outa[led] :=0
waitcnt(clkfreq*5 + cnt)
repeat
if CheckVolume == 1
magicir.play(led,@record,@recordlength)
waitcnt(clkfreq*20 + cnt)
MoniterRecording
Pub CheckVolume | x,condition
condition := 0
repeat x from 1 to 80000
if volume < 2250
condition := 1
x:= 400
result := condition
Pub MoniterRecording
repeat while CheckVolume == 1 'still picking up sound, keep recording another 20 seconds
waitcnt(clkfreq*20 + cnt)
magicir.play(led,@record,@recordlength) 'turn off recording after silence
DAT
record long 282388,418076,456550,487132,525613,626268,664743,695324,733804,764380
long 802853,833436,871568,902156,940628,971212,1009688,1040268,1078749,1109340
long 1147481,1178060,1216543,1247132,1285608,1316204,1354339,1384924,1423401,1524060
long 1562542,1593132,1631607,1662188,1700664,1731244,1769394,1799980,1838454,1869036
long 1907512,1938108,1976243,2077228,2115711,2216380,2254850,2355500,2393975,2424556
long 2463035,2493628,2532100,2562684,2600820,2631404,2669879,2770540,2809017,2839596
long 2878080,2908668,2947147,2977724,3016205,3046796,3084932,3115516,3153994,3184588
long 3223057,3323708,3362193,3462844,3501324,3531916,3570389,3600972,3639443,3740092
long 3778566,3879228,3917697,3948284,3986745,4017324,4055803,4156460,4194930,4225516
long 4263986,4364636,4403110,4503756,4542238,4572828,4611299,4711948,4750758,10702204
long 10984586,11119932,11158745,11189340,11227472,11328460,11366938,11397532,11436003,11466252
long 11504731,11535324,11573794,11604380,11642863,11673452,11711587,11742172,11780642,11811228
long 11849710,11880300,11918771,11949020,11987503,12018092,12056569,12087164
recordlength long 127
DAT
' Assembly program
'
org
asm_entry mov dira,asm_dira 'make pins 8 (ADC) and 0 (DAC) outputs
movs ctra,#adcpin 'POS W/FEEDBACK mode for CTRA
movd ctra,#fbpin
movi ctra,#%01001_000
mov frqa,#1
mov asm_cnt,cnt 'prepare for WAITCNT loop
add asm_cnt,asm_cycles
:loop waitcnt asm_cnt,asm_cycles 'wait for next CNT value (timing is determinant after WAITCNT)
mov asm_sample,phsa 'capture PHSA and get difference
sub asm_sample,asm_old
add asm_old,asm_sample
wrlong asm_sample, par
jmp #:loop 'wait for next sample period
'
'
' Data
'
asm_cycles long |< bits - 1 'sample time
asm_dira long |< fbpin 'output mask
asm_cnt res 1
asm_old res 1
asm_sample res 1
Made some code changes for adding the indicator light and I had an unintended pause before recording that I fixed.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
ir= 16 'IR led
led = 25 'red indicator light
'ADC microphone circuit on pins 21 22
bits = 12
fbpin = 21
adcpin = 22
VAR
long volume
OBJ
'vp : "Conduit" 'for viewport
magicir : "magicir_010"
Pub Main
cognew(@asm_entry, @volume) 'runs simple ADC code taken from code library
'vp.config(string("start:dso"))
'vp.config(string("var:volume"))
'vp.share(@volume,@volume)
dira[ir]~~
outa[ir] :=0
dira[led]~~
outa[led] :=0
repeat 6 'give some time for set-up before listening
waitcnt(clkfreq+ cnt)
!outa[led]
repeat
if CheckVolume == 1 'if sound picked up signal the camera to record
magicir.play(ir,@record,@recordlength)
outa[led] := 1 'turn on record indicator light on controller
waitcnt(clkfreq*20 + cnt) 'record for 20 seconds before checking for sound again.
MoniterRecording
Pub CheckVolume | x,condition
condition := 0
repeat x from 1 to 80000 'give a good chance for sound to be picked up.
if volume < 2260 'higher number more sensitive but get some false hits because of line gitter.
condition := 1
x:= 80000 'break out of loop on hit
result := condition
Pub MoniterRecording
repeat while CheckVolume == 1 'still picking up sound, keep recording another 20 seconds
waitcnt(clkfreq*20 + cnt)
outa[led] := 0
magicir.play(ir,@record,@recordlength) 'turn off recording after silence
DAT 'sequence for the remote control record button of my camera
record long 282388,418076,456550,487132,525613,626268,664743,695324,733804,764380
long 802853,833436,871568,902156,940628,971212,1009688,1040268,1078749,1109340
long 1147481,1178060,1216543,1247132,1285608,1316204,1354339,1384924,1423401,1524060
long 1562542,1593132,1631607,1662188,1700664,1731244,1769394,1799980,1838454,1869036
long 1907512,1938108,1976243,2077228,2115711,2216380,2254850,2355500,2393975,2424556
long 2463035,2493628,2532100,2562684,2600820,2631404,2669879,2770540,2809017,2839596
long 2878080,2908668,2947147,2977724,3016205,3046796,3084932,3115516,3153994,3184588
long 3223057,3323708,3362193,3462844,3501324,3531916,3570389,3600972,3639443,3740092
long 3778566,3879228,3917697,3948284,3986745,4017324,4055803,4156460,4194930,4225516
long 4263986,4364636,4403110,4503756,4542238,4572828,4611299,4711948,4750758,10702204
long 10984586,11119932,11158745,11189340,11227472,11328460,11366938,11397532,11436003,11466252
long 11504731,11535324,11573794,11604380,11642863,11673452,11711587,11742172,11780642,11811228
long 11849710,11880300,11918771,11949020,11987503,12018092,12056569,12087164
recordlength long 127
DAT
' Assembly program
'
org
asm_entry mov dira,asm_dira 'make pins 8 (ADC) and 0 (DAC) outputs
movs ctra,#adcpin 'POS W/FEEDBACK mode for CTRA
movd ctra,#fbpin
movi ctra,#%01001_000
mov frqa,#1
mov asm_cnt,cnt 'prepare for WAITCNT loop
add asm_cnt,asm_cycles
:loop waitcnt asm_cnt,asm_cycles 'wait for next CNT value (timing is determinant after WAITCNT)
mov asm_sample,phsa 'capture PHSA and get difference
sub asm_sample,asm_old
add asm_old,asm_sample
wrlong asm_sample, par
jmp #:loop 'wait for next sample period
'
'
' Data
'
asm_cycles long |< bits - 1 'sample time
asm_dira long |< fbpin 'output mask
asm_cnt res 1
asm_old res 1
asm_sample res 1
I didn't get too many of these game mission captures as my camera sound activation device
keep getting into reversals (turning camera off instead of on). Got some
more fine tuning to do, but still pretty happy with it as it gives me a way
of getting this information for my videos without having to have the Wayne's
World crew change what they are doing.
wow, the mic seems pretty sensitive! can you tell me what would be the practical application of this device? Also, if it's using IR controller, it needs to be in light of sight with the camera, right?
Practical? That's for each individual to figure out. My projects generally involve finding new ways to use
what I have without "hacking" them and affecting their re-saleability or re-pawnablity.
Yes, the IR light has to be pointed to the camera, which was a problem with it's first use. If the camera misses one command
it then turns off instead of on. I am going to attach the device to camera for next use, so nothing can get between. I also have
been meaning to look back at it again to see about adjusting mic sensitivity with a pot or something as the radio room had more noise (music and laptop computer) then
I had figured on.
Comments
When sound is detected it will signal the video camera to record for 20 seconds before checking for sound again. If sound is detected then it will
wait another 20 seconds before checking again. If sound is not detected it signals the camera to stop recording.
[video=youtube_share;YHOj21B4gjY]
keep getting into reversals (turning camera off instead of on). Got some
more fine tuning to do, but still pretty happy with it as it gives me a way
of getting this information for my videos without having to have the Wayne's
World crew change what they are doing.
[video=youtube_share;HwRY8aO6aEA]
what I have without "hacking" them and affecting their re-saleability or re-pawnablity.
Yes, the IR light has to be pointed to the camera, which was a problem with it's first use. If the camera misses one command
it then turns off instead of on. I am going to attach the device to camera for next use, so nothing can get between. I also have
been meaning to look back at it again to see about adjusting mic sensitivity with a pot or something as the radio room had more noise (music and laptop computer) then
I had figured on.