Interupt for analog (analogue) multi-task work-around - 1chip solution?

joshzstuff

New Member
Sorry for the wordy Title.
Target micro: Picaxe 08m2

I have an idea how I might be able to use 2 PicAxes in a surveillance application to immediately turn on/off the illumination circuit with the photo sensor input.
I only wish the light to start when 2 factors are true:
1) when the camera is recording
2) when the correct darkness level is sensed

I want the illumination to be able to start and stop during a recording (and remain off when not recording), so I wish to use an interrupt.
(The recording is triggered by a PIR sensor)

2 Micro method
Controller A:
-monitors motion sensor
-starts/stops recording
Controller B:
-continuously monitors READADC [photo sensor]
-starts/stops illumination
-triggers if controller A is recording

It would be a simple matter if the interrupt could be triggered directly when the READADC reached a desired level.

1 Micro/ multi-task solution . . ?​

Can I take advantage of the 08m2 multi-tasking and do this on a single chip?
Is there a way to get the attention of the program for this event immediately?
(Perhaps do I need to burn an input [leg 2 or 4] and program it to catch the attention of the interrupt?)
[I wish I had more outputs, I would consider moving to a 14m2 if it would open up better options]

I'm pretty sure I can dedicate a process thread to reading the analog sensor, but how can I interface the camera-side of my program?
Thanks for your input!
 

fernando_g

Senior Member
What type of Camcorder do you have?
Many Sony types have a control bus called Control-L (LANC). Google the term, there are plenty of results.

When I first used it for a stop motion photography project, the bus characteristics proved to be too formidable for my programming skills, so I purchased a a low cost controller, hacked the insides and interfaced to it.
 

hippy

Ex-Staff (retired)
You could possibly fake an interrupt on ADC level by adding the following task ...

Start1:
Do
ReadAdc pin, variable
If variable > value Then Gosub Interrupt
Pause sometime
Loop

You will probably have to add some extra code to stop interrupts triggering continuously but that should not be too hard to add.

There doesn't however seem to be any real need for interrupts, a two PICAXE solution nor multi-tasking so perhaps it's more a case of approach; defining exactly what the program needs to do rather than determining how it's going to do it.
 

joshzstuff

New Member
Thank your for your replies!
@ fernando
What type of Camcorder do you have?
Many Sony types have a control bus called Control-L (LANC). Google the term, there are plenty of results.

. . . so I purchased a a low cost controller, hacked the insides and interfaced to it.
That is sort of what I have.
It's a no name dvr/camera and I control very simply by hacking into the Power/On & Start/Stop record buttons.
I have the code complete for the PIR activated camera.
Here is a flow chart to show how it works:


@ hippy

There doesn't however seem to be any real need for interrupts, a two PICAXE solution nor multi-tasking so perhaps it's more a case of approach; defining exactly what the program needs to do rather than determining how it's going to do it.
Your right hippy, I may not need an interrupt. And I shouldn't be stuck on using one.

You could possibly fake an interrupt on ADC level by adding the following task ...

Start1:
Do
ReadAdc pin, variable
If variable > value Then Gosub Interrupt
Pause sometime
Loop

Ok, thanks! I think you have me thinking on the right track.

@ your example code template, let me make sure I have the correct principals down:

-The trick here is to increment a byte (or bit maybe) in my Cam code whenever it turns on and have it decrement when the Cam goes off.
-Then the code can turn ON the illuminator if the variable reflects BOTH the "Cam ON" bit & the Sensor bit. {see "2 variable approach"}
-The second thread (or 2nd micro) can simply compare the value of variable continuously (via loop command) and act accordingly (thus eliminating the need for an interrupt)

That right?

You will probably have to add some extra code to stop interrupts triggering continuously but that should not be too hard to add.
Was this applied only if I did decide to use an interrupt?
2 variable approach​
At first I was a little scared to use a single variable in the event that something happened to my camera code and the variable "ran away". I was thinking of comparing 2 separate ones instead (in case of 'run away') however I have a 'ani-run away' code line in my Camera program and if I reset the variable at that point it should provide pretty good stability.
 

vttom

Senior Member
This thread intrigued me. Here's food for thought on implementing this function with a single loop:

Code:
symbol Cam_Is_On          = bit0
symbol Cam_Is_Recording   = bit1
symbol Motion_Is_Detected = bit2
symbol Ilum_Is_On         = bit3
symbol Photo_ADC          = b1

Cam_Is_On = 0
Cam_Is_Recording = 0
Ilum_Is_On = 0

do

  ' Part 1 - Handle camera on events triggered by motion

  ' This subroutine should set Motion_Is_Detected to 1 if
  ' the motion detector senses something. Otherwise, set
  ' it to 0.
  gosub DetectMotion


  if Motion_Is_Detected = 1 then

    ' Reset the timer when motion is detected
    settimer t1s_4

    if Cam_Is_On = 0 then

      ' We land here if motion is detected and the camera is off

      gosub Turn_Cam_On
      pause 2000
      gosub Start_Recording
      Cam_Is_On = 1
      Cam_Is_Recording = 1

    elseif Cam_Is_Recording = 0 then

      ' We land here if motion is detected, the camera is on,
      ' and the camera is not recording.

      gosub Start_Recording
      Cam_Is_Recording = 1

    endif

  endif


  ' Part 2 - Handle camera off events triggered by timeouts

  if Cam_Is_Recording = 1 and timer > 30 then

    ' We land here if 30 seconds have elapsed without motion
    ' and the camera is recording

    gosub Stop_Recording
    Cam_Is_Recording = 0

   elseif Cam_Is_On = 1 and timer > 95 then

    ' We land here if 95 seconds (30 + 65) have elapsed without
    ' motion and the camera is on but not recording

    gosub Turn_Camera_Off
    Cam_Is_On = 0

  endif


  ' Part 3 - Handle illumination control triggered by photo detector

  if Cam_Is_Recording = 0 then

    ' We land here if the camera is not recording

    gosub Turn_Ilum_Off

  else

    readadc 3, Photo_ADC

    if Photo_ADC < (some threshold) and Ilum_Is_On = 0 then

      ' We land here if the camera is recording, the photo detector
      ' tells us it's dark outside, and the ilumination is off

      gosub Turn_Ilum_On
      Ilum_Is_On = 1

    elseif Ilum_Is_On = 1

      ' We land here if the camera is recording, the photo detector
      ' tells us it's light outside, and the ilumination is on

      gosub Turn_Ilum_Off
      Ilum_Is_On = 0

    endif

  endif

loop
 

joshzstuff

New Member
This thread intrigued me. Here's food for thought on implementing this function with a single loop:
I'm glad you are interested vttom, Thank you for the Idea and your code!

I wrote some corresponding subroutines and started doing simulations based on your code, however I ran into an error with the SETTIMER command:

Code:
 settimer t1s_4
                  ^

Error: 'settimer' command not supported by this chip!
I had to rem out that command to proceed with my simulations.
I set the Programming editor for the 08m2, I also tried other m2 parts but I couldn't find a chip that let me use the command.
Any thoughts?

One aspect of the DVR that I'm using is that it times out itself if is left in 'standby mode' (after a recording finishes) for 65sec.
Because of this I don't turn the Cam off, but allow it to shut down itself from 'standby mode'
(and i hold the program in an appropriate pause to keep any inputs from triggering before the short reset period passes)

I appreciate the simplicity of your code made possible by using variables.
In my previous code I simply used pauses for the time intervals.

HERE is an early version of the camera code.

I will warn you though, it's a little rough to follow thanks to my crude coding techniques, :eek: of which I was reprimanded for.
However, because of this constructive criticism I have since improved (somewhat :eek: )

Note: I changed the attached picture in the first post to simplify the ports, color Identify inputs/outputs, and added the missing connection for the Motion detection.

Thank you for all of your help!
 
Top