Go Down

Topic: Output multiple timers on one pin (Read 476 times) previous topic - next topic

edmcguirk

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.

Paul_KD7HB

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

Paul

TonyWilk

Hi,

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

Quote
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

MorganS

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.
"The problem is in the code you didn't post."

TonyWilk

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:

Quote from: 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

edmcguirk

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:
https://www.youtube.com/watch?v=we9IZJ5tQFs

edmcguirk

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.

edmcguirk

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?

Paul_KD7HB

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

Paul

TonyWilk

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




edmcguirk

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.

TonyWilk

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

aarg

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.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

edmcguirk

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?

edmcguirk

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.

Go Up