3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Crossed IR Beam Camera/Flash Trigger

Step 2The Program

The PIC10F206 is a really simple part- no interrupts and only a 2 level stack, so you can't do any nested subroutines- you'll see liberal use of goto's in the program as a result. The chip is running at 4 MHz using the internal RC oscillator so it executes 1M instructions per second. When an object breaks the IR beams, it takes the IS471 chips abut 400 us to change state. From there the uC needs just a few microseconds to detect the change and order the relay to close. The relay takes about 1.5 ms to close resulting in about a 2 ms total delay from beams broken to relay closed.

I developed the program chip using MPLAB. It is Microchip Tech's free assembler/IDE. I also used my Chinese ICD2 clone (about $50 on ebay) to actually program the IC. I needed to use a lot of delay loops so I rooted around on the web and found a program called PICLoops here:
http://www.mnsi.net/~boucher/picloops.html
PICLoops automatically generates timing loop assembly code for you if you tell it what uC you are using and the clock speed. Later on I ran into a similar on-line program here:
http://www.piclist.com/techref/piclist/codegen/delay.htm
The second one will generate delays that are accurate to a single clock cycle where PICLoops isn't quite so accurate. Either is fine for this app because timing isn't critical and the uC is running on an RC oscillator anyway.

The program mainly bops back and forth between checking the mode button and checking to see if the beams are interrupted. The mode switch works by keeping a running count of the number of times the button has been pressed. Each time the button is pressed the delay between the pulses to the relay gets shortened enough to step the pulse frequency by 1 Hz. The biggest part of the code is the different delays used by the pulse modes.

When you change the pulse mode the LED flashes to indicate the new mode. You can tell what the new pulse frequency is by counting the LED flashes- 4 times means 4 Hz, etc. The LED flashes have been timed slow enough that you will be able to count them. If the unit is in 10 Hz pulse mode, pushing the button again takes you back to continuous mode.

There is a watch-dog timer that runs while the program runs. If the timer isn't reset before it overflows, the uC will reset itself. That is why holding the mode button for 2.3 seconds causes the uC to reset to continuous mode. When you push the button, the uC waits for you to release it before doing anything. One of the first things it does after you release it is reset the watch-dog timer. If you don't release the button, the watch-dog timer overflows and restarts the program in the continuous mode.

I have attached the assembly listing file for those who are curious and the .hex file for those who just want to burn the chip and be done with it. I welcome any criticism of my programming technique from any of you PIC assembly experts out there.

Note- the relay closes for 25 ms when it operates in pulse mode. Some cameras may require a longer pulse. That delay is set in line that says "call delay25" near the top of the rlypuls section of the code. If 25 ms is too short for your camera, change that line to say "call delay50", then change the line that says "call delay75" to say "call delay50". That will increase the pulse time to 50 ms and still keep all the pulse frequencies at even 1 Hz steps.

The program only occupies 173 bytes out of the available 512 bytes in the chip, so you can add all sorts of functionality to the thing if you desire, though the user-interface is going to be somewhat limiting.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
17
Followers
6
Author:Mark Rehorst(Mark Rehorst's Projects Page)
I was electrical engineer for 22+ years, then went back to school and became a dentist.