0
votes

I will give you a little introduction:

I am working on a water fuel cell of Stanley Meyer. For those who don't know the water fuel cell you can see it here.

For the water fuel cell one has to build a circuit. Here is the diagram:

Water Fuel Circuit

Right now I am working on the pulse generator (variable) and the pulse gate (variable) to generate this waveform.

Pulse train

So, I want to do this with Arduino timers. I already can generate a "high frequency" pulse generator (1 kHz - 10 kHz, depending on the prescaling at the TCCR2B register) PWM at pin 3 with this code:

pinMode(3, OUTPUT);
pinMode(11, OUTPUT);
TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS21) |  _BV(CS20);
OCR2A = 180;
OCR2B = 50;

I can modify the frequency and pulse with:

sensorValue = analogRead(analogInPin);
sensorValue2 = analogRead(analogInPin2);

// Map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 30, 220);
outputValue2 = map(sensorValue2, 0, 1023, 10, 90);
OCR2A = outputValue;

This is working fine.

Now I want to modulate this pulse with another pulse train with "low frequency" (20 Hz to 100 Hz approximately) to act as a pulse gate. I was thinking to use Timer 0 to count and shutdown the signal when it counts some value and activate when arrives at the same value again, like this

TCCR0A = _BV(COM0A0) | _BV(COM0B0) | _BV(WGM01);
TCCR0B = _BV(CS02);
OCR0A = 90;
OCR0B = OCR0A * 0.8;

And compare with the counter

 if (TCNT0 <= OCR0A)
     TCCR2A ^= (1 << COM2A0);

But it does not work well. Any ideas for this?

1

1 Answers

0
votes

These days I have tried to create a wave generator like the one that comes in your question. I can not eliminate the jitter or mismatch that appears, but I can create a wave like that. Try this example and modify it:

#include <TimerOne.h>

const byte CLOCKOUT = 11;
volatile byte counter=0;

void setup() {
    Timer1.initialize(15);  // Every 15 microseconds change the state
                            // of the pin in the wave function giving
                            // a period of 30 microseconds
    Timer1.attachInterrupt(Onda);
    pinMode(CLOCKOUT, OUTPUT);
    digitalWrite(CLOCKOUT, HIGH);
}

void loop() {
    if (counter>=29) {         // With 29 changes I achieve the amount of pulses I need.
        Timer1.stop();         // Here I create the dead time, which must be in HIGH.
        PORTB = B00001000;
        counter = 0;
        delayMicroseconds(50);
        Timer1.resume();
    }
}

void Onda(){
    PORTB ^= B00001000;   // Change pin status
    counter += 1;
}