Background running program

I was wondering if it is possible to run a function in parallel with the main loop. What I am trying to do is run an interrupt with a delay to turn on and off a output but at the same time I want to keep the main program running. I am not to worried about the main program but making sure the interupt function works ( runs at 120hz).

Thanks for the help!

An interrupt is only an input as far as I know. So on that basis you could use another timer IC to pulse an input which you could use to ensure you call your subroutine to invert your output pin.

How critical is your 120Hz output? If this could float between 120-122Hz, I don't see why you couldn't just have a subroutine that compares the current millis to your previous execution millis, and if enough time has passed, invert your output pin? You could call your this sub routine between each section of your main program (depending how heavy your main loop is) to ensure you didn't miss it. Hope that makes sense.

I will play with it some more tonight. I might need to have a seperate micro to just do what I want. The timing is critical because I am using it to dim a light http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230333861.

The problem I was running into is that I cannot have any delays in m main program or the interrupt will not fire the triac properly.

Just FYI, there are these "touch dimmers" for lamps for like $10, I imagine they could be dissected or otherwise controlled by a micro controller:

Yes I know about those. I am not using that because 1) I want to learn how these things are built anyway and 2) because I might e making a few controllers for some friends ( there going to end up controlling a fan)

"because I might e making a few controllers for some friends ( there going to end up controlling a fan) "

You might run into problems trying to drive an inductive load like a fan with a triac designed for lighting or other resistive loads. It's a Dv/Dt thing and can be compensated for with external caps and resistors, but the details escape me so you might have to search around the net if you experience trouble starting and stopping a motor. A lot depends on the actual amount of inductive reactance of the load, smaller fan motors might work fine, experiment.

Good luck

Lefty