Beginner - 100 microsecond delay timer

Discussion in 'Embedded Systems and Microcontrollers' started by merc07, May 6, 2009.

  1. merc07

    Thread Starter Member

    May 6, 2009
    17
    0
    Hi, my 1st post....

    What I am after is a simple delay timer, running from 0 to say 100 milliseconds in steps of 0.1 milliseconds, with a display of the set time.

    Two input buttons would be used to set the time (up or down)

    Basically I will have a switched input, delay by X amount, then the output is triggered. Complete accuracy is not vital as long as it is constant.

    Is this possible, if so where is the best place to start with the hardware. - PIC selection, display, USB Programmer?

    Programming shouldn't be a problem apart from the output display maybe, and I'm ok with the PCB work - just never used PIC before.

    Thanks,
    Adam
     
  2. DonQ

    Active Member

    May 6, 2009
    320
    11
    Your title says micro, but your text says milli.

    Virtually any PIC, with enough pins to read the buttons and drive the output and the display you choose, would work. The trick may be to see if, by using a serial input LCD display, you could do it entirely with an 8-pin PIC.

    Most include a reasonably accurate internal clock, so you could do this with minimum support hardware. I've built a number of timing circuits consisting of only an 8-pin PIC and a power supply bypass cap and an I/O connector.
     
  3. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Just had a few questions for you:
    So the input is a pushbutton?
    What does the output connect to?
    How constant/repeatable do you need it to be?
     
  4. merc07

    Thread Starter Member

    May 6, 2009
    17
    0
    I'll explain what I need it for, that should help.

    I have two DSLR cameras trlggered by a single infrared trap and a radio transmitter. The cameras have separate receivers. I need them to operate at the same time to 'share' the light from a single flash triggered from one camera.

    The cameras are different models and therefore have different shutter delay times, about 18 milli seconds - flash duration is a lot less.

    I have it working at the moment by using multi sync flash set at the correct frequency (2 fashes 18ms apart) but that's twice the flashes, half the battery life and I want to use radio flashes as well which are too slow for multi sync.

    Yes, I could possiby run it in milliseconds but I thought if simple enough, why not step in micro's.

    So in short, the input would be from the receiver signal, (high or low), the output would need to oparate a reed relay (0.5ms switch time) to trigger the camera.

    Once set at the correct delay, constant and repeatable is what I need.

    Thanks, Adam
     
    Last edited: May 7, 2009
  5. merc07

    Thread Starter Member

    May 6, 2009
    17
    0
    Can you give me an example of a development board / pic that would be suitable. I have looked at various sites but I just don't know where to start.

    Thanks,
    Adam
     
  6. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    For microsecond-scale resolution and accuracy you should probably go with an external crystal or clock. They will be more stable and drift less than the internal oscillator. You are also going to want to use a interrupt-driven hardware controlled timer. In the PICs they have a capture/compare mode for the timer (ECCP).
    The PIC12/16 are 4 clocks per instruction.
    The PIC16F690 might be good one for you. It has ECCP (section 6) SSP (Section13) for I2C or SPI for the LCD and a EUSART (section 12) for UART. Port A has interrupt on change functionality which you'll want also.

    Also look at the Hi-Tech C PRO compiler (Lite-Mode) and a PICkit2 starter kit (has a PIC16f690 and programmer)
     
  7. Vaughanabe13

    Active Member

    May 4, 2009
    102
    5
    Also, keep in mind that if you want to have a delay range up to 100ms in increments of .1ms or less, you might not want to use pushbutton switches. If you were delaying from 0-100ms, it would take 1000 presses of the button to go from one end to the other in increments of .1ms, and that would take forever. You could solve this by checking to see if the button is being pressed or held down, or you could use a rotary pulse generator and write a function that checks if the RPG is being turned fast or slow, and adjust the delay time from there.

    I would also recommend using a crystal for such small delay times.

    You might also consider a small usb-based programmer like this one:
    http://focus.ti.com/docs/toolsw/folders/print/ez430-f2013.html
     
  8. merc07

    Thread Starter Member

    May 6, 2009
    17
    0
    Thanks for the quick responses, I'll have a look at the boards tomorrow.
    It seems like using 0.1ms as the step might be making this overly complicated for a first time project.
    To get me started, if I were to use 1ms steps, 0-99, could I then utilize the pics internal timer ?
    The coding would be simpler and I would just need 2x 7 segment lcd's instead of 4.
    Thanks, Adam.
     
    Last edited: May 7, 2009
  9. DonQ

    Active Member

    May 6, 2009
    320
    11
    "Also look at the Hi-Tech C PRO compiler (Lite-Mode) and a PICkit2 starter kit (has a PIC16f690 and programmer) "

    This is good advice, especially the HiTech Compiler.

    Some other suggestions...

    Since you will probably only want adjustment for the testing phase, you might try just using a serial port and a terminal program on a PC for setting the delay value. It would be easy to use "+" and "-" keys to inc/dec the value. Other keys could inc/dec it by 10's or by 100's. This would give you a wide range of adjustments.

    The display could be replaced by simply outputting the current values to the terminal screen. Once you find the proper value, you would "hard-code" it into the program, disconnect the terminal and have a minimum system to include in whatever your overall device is.

    I've been doing this longer, so this may not be the way you would want to approach your first PIC project, but for something as simple as this, I would use an 8 pin PIC (something like the 12F508/9, about 40 cents), "bit-bang" a serial port, and use the internal clock (the internal clock is fine for short time delays. It won't drift even 1% over the temperature range you will be using it, not enough to matter in your application.)

    This would end up with the entire project consisting of a single 8-pin chip, with maybe a single power bypass capacitor, and nothing else!

    A first project may be better done with a 14/16 pin chip, one with a built-in serial port.

    Interrupts are fine, but overkill for a simple delay in your first project.
    Once you determine the delay value you need, code as simple as something like this would implement a minimum system.
    Code ( (Unknown Language)):
    1.  
    2. while (true) {
    3.   counter = ####;     // whatever value your tests shows works best
    4.   while (!input);     // waits till input true
    5.   while (--counter);  // counts down till equals zero
    6.   output = true;
    7.   counter = 1000;     // delay long enough for a reasonable output pulse
    8.   while (--counter);  // counts down till equals zero
    9.   output = false;
    10. }
    11.  
    12.  
    The speed at which while(--counter) decrements will depend on what type of variable you use for 'counter', but even for a long int, it will still have a resolution of a few microseconds, and a range of up to many seconds. More than what is needed.

    Once you get something like this working, then you can get fancy with things like interrupts, saving values in onboard EEPROM, and all sorts of other stuff.

    I could also write code that spanned pages and pages, and ate up kilo-words of program memory, and took a "rocket-scientist" to understand. The end result would be the same as the above code... Wait for an input, delay a fixed interval, then pulse an output... repeat.

    Doing it in a single chip, with just a handful of program words, is really all that is needed to get the job done. Learning more about what all the possibilities can happen easily after you get your first system working.
     
  10. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Why not trigger the flash from the camera with the longest shutter lag? As long as the shutter speeds are reasonably slow, both shutters will be fully open when the flash goes off.
     
  11. merc07

    Thread Starter Member

    May 6, 2009
    17
    0
    That would work ok if the riders didn't have lights. On the first camera I don't want any 'light beam' so I need a shutter speed of at least 1/100th (0.01s). From what I have read the difference in shutter speeds is supposed to be 0.035s (1/30th) but I seem to have it working ok by delaying the second flash by about 0.0083s - this may be just down to the flash timing itself ? I have tried the flash on the other camera and at 1/100th it misses the flash completely. I also wanted to use radio flashes which add even more delay.

    See examples below. In the 1st pic, the flash is delayed by 1/60th, in the 2nd shot it is delayed by 1/120th from the shutter of the 1st camera. The difference in flash times in the two shots is just 0.0083s

    In any case it's an excuse to build another gadget. I have downloaded the Hi-Tech C Pro Lite version and I'm about to order the PICkit2 starter kit as suggested.

    Cheers
    Adam
     
    • 1.jpg
      1.jpg
      File size:
      44.3 KB
      Views:
      26
    • 2.jpg
      2.jpg
      File size:
      55.5 KB
      Views:
      28
    Last edited: May 10, 2009
  12. merc07

    Thread Starter Member

    May 6, 2009
    17
    0
    Thanks, I got around this by 1st incrementing in 50us (0.05ms) then the longer the button is held, the higher the increment goes - up to 1ms steps.

    I'm almost done but one more question.

    I have written it in PicBasic that came with the PICkit2 and used the 16F690 that also came with it as I am using 4 x 7 segment displays to show the delay speed. It also has the on chip oscilator.

    I want to be able to write the last set Delay speed back to the chip so that when I next use it, the data can be read back as a starting point.

    I'm not sure if I can use the WRITE command with the 16F690, or the WRITECODE command or what address to write to.:confused:

    Thanks
    Adam
     
Loading...