Timers and frequencies

Hello, I have an Arduino Mega 2560 So, I need to get a signal out of it, It needs to have a frequency in the range of 200 Khz but can go down to 50 Khz or less, I need the signal to be extremely accurate and reliable, So it seems to me that running Timer 1 at those frequencies is not so reliable as there are random delays and some general dirt in the signal, And since i have the Mega i though of this..

We have Timer 1, 3, 4 and 5, All are 16 bit, Why not run two or three of them at the same frequency, Then check them against each other for mistakes? If a timer makes 5 mistakes in places, The other timers make 5 mistakes in other places, We check them against each other the result is a cleaner signal, Is this possible to do this with an arduino board?

I think it should be simple to do that.

Not reliable ? mistakes ? I don't understand. When you program an internal hardware timer for a certain frequency and have the output go to one of the pins, the output is as accurate as the 16MHz crystal. There will be absolutely no mistakes.

You can not create every output frequency, since the 16MHz is divided with a whole number.

I think the toneAC and toneAC2 can do that: http://playground.arduino.cc/Code/ToneAC

Yes but you can use compare match to get frequencies like 55 khz or 79 khz etc, The prescale would be 1 too.

Yes, you can divide by 45 and 46, but not 45.5 But I don't know what your question/problem is.

Well, I am using the arduino to directly drive a half bridge of Mosfets, The signal i get out of a half bridge is not uniform and it seems like there are some pulses skipped.

Impossible. Did you connect the grounds ? Do you use fly-back diodes ? Did you avoid ground currents ?

The ground is connected, There is also a good RF field around the circuit, But can that quite cause skipped pulses or even ones longer than usual

Timers are hardware; once set up they run perfectly consistently. Nothing going on in the MCU should affect them (except of course reconfiguring the timers). External influences are something else again, any circuit can be affected by external fields to a greater or lesser extent depending on its design and the strength of the field.

Hmm, Maybe i should shield the arduino in a metal case to avoid interference with anything? (What does MCU stand for?)

MisterKitten: Hmm, Maybe i should shield the arduino in a metal case to avoid interference with anything? (What does MCU stand for?)

MCU = Microcontroller Unit, i.e. the Arduino.

Depending on the nature and strength of the RF field (describe?) shielding may be appropriate.

[quote author=Jack Christensen link=topic=258313.msg1825689#msg1825689 date=1406844462]

MisterKitten: Hmm, Maybe i should shield the arduino in a metal case to avoid interference with anything? (What does MCU stand for?)

MCU = Microcontroller Unit, i.e. the Arduino.

Depending on the nature and strength of the RF field (describe?) shielding may be appropriate. [/quote]

Well, The half bridge is used to drive a high voltage transformer at resonance, Which happens to be a high frequency, The result is about 80 Kv at high frequencies, Enough to light fluorescent lights at a good distance (About 2 meters), So it is a pretty strong RF field, It was kind of stupid not to use proper shielding anyway.

That's very cool, and dangerous and it brings back memories. I get about 10 or 30 times more voltage out of a transformer at resonance frequency. Perhaps with your transformer it is even more.

That is also inductive, can you show us the schematics or a drawing of the H-bridge ? At resonance frequency, the H-bridge generates a square wave, however the current through the transformer is completely different. But as far as I know, the square wave does not have a negative influence on the efficiency.

Are there wires between the Arduino and the H-bridge ? longer than 10cm ? Keep in mind that using optocouplers is a good option. To isolate the Arduino from the high power / high voltage circuit.

You could use the Arduino to find the optimum frequency :P

Here is a schematic of my H-Bridge http://prntscr.com/48c1xx

There is a GDT for good isolation, The arduino goes straight into the gdt, The wires are rather short and shielded, Also Resonance really is black magic :) I calculated the resonant frequency of the transformer, However as usual, Calculations aren't quite 100% accurate as they expect optimum conditions and that is not usually provided by hobbyist gear, But at least they give you a place to start

Well that sounds exciting!

Do you have an Arduino output connected to one of the GDT (Gate Drive Transformer) coils ? I have not seen an Arduino connected like that.

Peter_n: Do you have an Arduino output connected to one of the GDT (Gate Drive Transformer) coils ? I have not seen an Arduino connected like that.

Of course, There are three coils on the GDT, The arduino's output is on one of the three, The schematic was found online and modified ever so slightly then run with an arduino, But again, The unstable signals are again, Most probably nasty electromagnetic fields interfering with the arduino, A random wire or the bridge itself, I might have to find a metal box, Perhaps an old computer PSU could work, Those also have massive fans and nice ventilation

Also it indeed is very exciting.. And shocking! ]:D

Edit: Yes i have a horrible enough editing skill to point an arrow in that horrible way

I shielded my entire arduino, The problem persists, Perhaps there are delays during executing code? Arduino flawed? I set it to 280 Khz, Only 250 came out, I tried setting it to 1 Mhz, It was rather accurate, 999300, Help?

When you use a hardware timer it is as accurate as the 16MHz crystal. The output of a hardware timer is completely independant of the sketch, the interrupts, the delays, or whatever. Do you use a hardware timer ? I don't think so, and if you do, the sketch is wrong.

Well, I am 99% sure that timer.1 is the one running, I also tried digitalWrite-ing on and off every 10 microseconds and got some 40-30khz.

We can't help if we don't know what you are doing. So far we have a part of a schematic. The Arduino output to the GDT could be wrong, resulting in missed gate triggers. Maybe you use TIMER1, but we don't know which library or sketch you are using, so we don't know if you are using the hardware timer output, or a software interrupt generated pulse. I don't even know at what point you measure the frequency.