Output multiple timers on one pin

Ok, I'm a noob so I hope I am asking the right question. I am using an arduino micro.

Actually I am trying to drive two pins but both controlled by two timers.

I am trying to drive two vibratory pumps. They act like solenoids that need 50hz pulses to drive them. I want to switch 220V DC 50 times per second with a mosfet. Therefore a high output at the arduino will turn the mosfet off and a ground will turn it on. I want to fire the mosfets alternately because I do not want both pumps drawing current at the same time. Therefore one pin for each pump/mosfet.

Once I have the program set up to supply 50hz pulsed DC alternatively to two pumps, I want to throttle the power. I want to supply full 50hz power cycles but suppress cycles for 5 different power levels. For example, 20% power would be 5 cycles on followed by 20 cycles off and 60% would be 15 cycles on and 10 cycles off. In other words the 50hz DC would be PWM at 2hz. Both pumps active or inactive at the same time, at the same power level.

I assume I could do all this with an ISR and writing to pins directly but I would rather drive pins directly from the timer in order to minimize any time interactions between my programming and the pin status.

Since I am new to arduino I recognize I might be asking the wrong question or trying to do the impossible.

First question - Can I drive 2 pins at 50hz from one timer so that one pin is the opposite of the other?

Second question - Is it possible to drive an output pin directly from the the logical comparison of one timer and another without an ISR? Or instead keep an active 50hz output but suppressed (high) 2 times a second?

Since I am controlling 220V, I want to minimize the possibility of outputting anything but 50hz or off.

I am trying to avoid adding more circuit components. I would like to avoid adding a 555 timer at 50hz and turn it on or off 2 times a second. I would like to avoid putting 50hz output on one pin and then blocking the signal with output from another pin. However I will use one of these if I can't reliably get what I want directly.

Consider just inverting the signal before sending to the other mosfet. Problem solved.

Paul

Hi,

Looks like you do need two separate outputs to independently drive the two pumps at varying power levels.

Since I am controlling 220V, I want to minimize the possibility of outputting anything but 50hz or off.

I would suggest you AC couple the drive to the mosfets to give you some hardware 'insurance' against leaving one or both on all the time.

Driving at 50Hz gives you quite a bit of time ( 10mS on, 10mS off), you could do that by timing the outputs using millis()... have a look at this very simple Blink Without Delay example

Yours,
TonyWilk

The timer hardware in even the most basic Arduinos is extremely capable. Pretty much anything you can think of has been designed into the hardware. But getting to that capability is difficult. The datasheet does have all the information but not in a form that can easily be written into an Arduino program.

My interpretation of what you need is two PWM signals, which are synchronized. You only want to drive each one of them in the 0-50% range and you want them synchronized so that when they're both at 50% they don't overlap. You may, for example drive one at 25% and the other at 50% but they always stay locked in frequency so that they're never both on at the same time.

I'm sure this is possible with at least some of the Arduino variants. Personally, I don't believe it's worth the time digging into the datasheet. Just set up a timer ISR and drive the pins "manually" in your code.

I'm still not clear on the requirement. You're driving vibrators which presumably resonate at 50Hz, at least the mechanical resonance is around that frequency. Electrically, they're probably big coils of wire with a big inductance, giving an electrical resonance. To drive these efficiently (without burning the coil or the driver) you need to know what that resonance is. You seem to be ignoring the "off" half of your drive signal. That is just as important as "on". I would expect to drive them with a full sine wave which goes positive and negative. A modified sine wave or trapezoid may be useful, depending on the drive electronics you have.

MorganS:
My interpretation of what you need is two PWM signals, which are synchronized. You only want to drive each one of them in the 0-50% range snip

I read this:

edmcguirk:
I want to supply full 50hz power cycles but suppress cycles for 5 different power levels. For example, 20% power would be 5 cycles on followed by 20 cycles off and 60% would be 15 cycles on and 10 cycles off.

and thought they meant to "burst-fire" full cycles ?

edmcguirk: Will the drive to each pump only ever be [1] full cycle(s) at 50Hz (10mS on, 10mS off) or [2] off for period(s) of 20mS?

If this is the case, you simply want 10mS timeslots to turn the outputs on or off.

Yours,
TonyWilk

These vibratory pumps normally work on 50hz 220v ac however an internal diode makes them work equally well on 50hz pulsed dc at 50% duty cycle. Square waves actually work better than sine waves. I am starting from 12v dc through a boost inverter rectified to 220v dc.

Since I am using the pumps for a pressurized spray where atomization is a priority, I believe intermittent full power will work better than continuous reduced power. (testing will prove or disprove that)

I know I can create the output signal programatically but I thought a 'set and forget' output from the timer would be more reliable. Obviously I could just get an interrupt 50 times a second and then just set the output to whatever I want. If possible, it would be nice if the rest of my program did not need to acknowledge the existence of time. Once I get involved with interrupts, it's probably just easier to do it all in an ISR.

Getting a simple 50hz output seems easy to do but I don't know if it's possible to have a second output with phase locked opposite polarity without resorting to interrupts and programming.

Getting a second timer at 2hz to directly interact with the 50hz timer seems impossible and I was just hoping I could be proved wrong there.

If anyone is interested a good description of the pump is found here:

Paul_KD7HB:
Consider just inverting the signal before sending to the other mosfet. Problem solved.

Paul

Sometimes I get a little hung up on eliminating circuit components but that is an option if I cant do it in software.

Maybe I haven't ought this all the way through. Inverting the output doesn't even cost me another component. It actually saves me a resistor.

Maybe it's simplest to do it mostly in hardware.

Is the attached drawing correct?

That's the idea, but I am not qualified to comment on the circuit.

Paul

edmcguirk:
Getting a simple 50hz output seems easy to do but I don't know if it's possible to have a second output with phase locked opposite polarity without resorting to interrupts and programming.

Getting a second timer at 2hz to directly interact with the 50hz timer seems impossible and I was just hoping I could be proved wrong there.

I think it's pretty simple:

  • Everything happens on 10mS intervals
  • for now, it doesn't matter if this is a main-line code delay thing or a 10mS interrupt
  • Every 10 mS you have to:
    a) Increment some "StateCounter" to handle "burst firing"
    b) toggle a 'phase' variable... every 10mS you are either in Phase 1 or Phase 2
    c) If you are in Phase 1, set output 1 HIGH (if reqd), set output 2 LOW
    If you are in Phase 2, set output 1 LOW, set output 2 HIGH (if reqd)

The "StateCounter" could be a number which cycles from, say, 0 to 255
The required power level for either output is a number 0 to 255
The decision to output a HIGH for that output is simply: "StateCounter" < "PowerLevel"

No messing with second timers. The ONE timer source which gives you 10mS is all you need.

Job done.

Yours,
TonyWilk

Yes, I will probably end up doing it that way. I just liked the idea of setting a timer to run in the background. Then I don't have to actually trigger events, I just change the PWM percentage as needed.

I always feel that there will come some point when my program will get lost and 220v will go 100% and fry the coils.

edmcguirk:
I always feel that there will come some point when my program will get lost and 220v will go 100% and fry the coils.

If your program 'got lost' there's no guarantee that the software-controlled timer(s) would continue to work uninterrupted. Neither would timers guard against resetting the device or in a 'brown-out' condition.

So, I say again:

I would suggest you AC couple the drive to the mosfets to give you some hardware 'insurance' against leaving one or both on all the time.

Yours,
TonyWilk

TonyWilk:
If your program 'got lost' there's no guarantee that the software-controlled timer(s) would continue to work uninterrupted. Neither would timers guard against resetting the device or in a 'brown-out' condition.

So, I say again:

I would suggest you AC couple the drive to the mosfets to give you some hardware 'insurance' against leaving one or both on all the time.

Yours,
TonyWilk

It should also be protected with a fuse.

I'm not familiar with ac coupled mosfets.
Is the attached circuit the correct way to do that?
Are those good values for 50hz?
Can you point me to someplace where I could find simple guidance on a good design?

aarg:
It should also be protected with a fuse.

There will be fuses, relays, switches, and other protections outside the other components that will make up this project.

edmcguirk:
I'm not familiar with ac coupled mosfets.

Cooked this up as an example:
Diagram:

To turn on the MOSFET the output pin has to be driven LOW (this allows for RESET where the pin is not driven)

When the output goes LOW, the (uncharged) capacitor 'pulls down' the transistor base and turns it on - but only until the capacitor is charged - and then the transistor turns off again even though the output pin was left low.

This "automatic turning-off" only happens if the output is held low for too long (40 - 50mS or so), normally your working software would turn the output off (back HIGH again) after 10mS

I stuffed an opto in there to isolate the MOSFET drive, I think the 4N25 is fast enough with the additional base resistor.

The output MOSFET is only shown here driving a dummy load on 12V.
(the part no. is not an actual recommendation, I just plucked a high voltage one for the diagram)

You will need to sort out your 220V and protection stuff to drive inductive coils.

Yours,
TonyWilk