Variable DC to Variable AC circuit

Thread Starter

Mike ER

Joined Jan 13, 2023
2
I am a hobbyist and am looking to solve a specific problem. I need the ability to convert variable DC ( 0-20v) to the equivalent AC voltage. I have been researching ardinuo spwm to convert the DC to AC. I am thinking about using a 1:1 CT transformer to complete the link but can't find one so may have to wind it myself and adjust as necessary. My real questions are will the DC circuits even work until a minimum of ~6V is being supplied? Not really sure if there are some better ways to do what I am trying to achieve. Any help/guidance would be appreciated.
 

BobTPH

Joined Jun 5, 2013
8,954
Are you expecting to power the circuit from the DC source? If so, 0-20V is out of the question. If you use an external power supply, it can go down to zero.

What are going to use this for?
 

Thread Starter

Mike ER

Joined Jan 13, 2023
2
Are you expecting to power the circuit from the DC source? If so, 0-20V is out of the question. If you use an external power supply, it can go down to zero.

What are going to use this for?
The circuit will be powered. I had planned to use a 12v DC source which I can drop to 5v to power an arduino or whatever control circuit I use. The real challenge for me is to convert the DC input to a following AC output. The use is for model railroading. I am moving all my computer sensors/controls/throttles, etc from HO (DC) to legacy Lionel (AC). I have advanced computer controlled throttles and I would like to find a way to convert the DC output to AC output. Everything I can find wants to go from fixed DC to a fixed AC and I am trying to figure out a way to do variable. Anything you can suggest is appreciated.
 

Papabravo

Joined Feb 24, 2006
21,225
So, the critical question is: do you expect the AC output to scale with the DC input down to 0 VDC? I was thinking that you might be able to get close but I'm not sure I can eliminate all the losses from a full bridge inverter.

I ran an admittedly optimistic theoretical simulation of a half bridge inverter down of 0.5 VAC(rms). Specifying real components to do this might be a challenge.
1673666608295.png

.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,802
You need to take a different approach.
Get a low voltage transformer to provide the required AC voltage. Use a light dimmer switch to control the AC voltage.
Now use the DC voltage to control the light dimmer. For that, I would try an LED and LDR combo as an opto-isolator.
 

Papabravo

Joined Feb 24, 2006
21,225
You need to take a different approach.
Get a low voltage transformer to provide the required AC voltage. Use a light dimmer switch to control the AC voltage.
Now use the DC voltage to control the light dimmer. For that, I would try an LED and LDR combo as an opto-isolator.
Don't lamp dimmers use triacs to modify the waveform? I'm not certain the locomotive motor would be happy with that,
 

nsaspook

Joined Aug 27, 2009
13,265
If you have Arduino experience and hardware it's not too hard.

An adc input on a controller (with the correct voltage divider to convert to 3.3 or 5vdc) could easily easily convert the 0-20 DC signal to a 10 or 12-bit digital value that could be used as a control value for the PWM duty cycle for SPWM AC voltage level control. The Arduino would be a good starting platform for such a project if you only have 50-60Hz fixed frequency AC.

https://github.com/Irev-Dev/Arduino-Atmel-sPWM

The trick is to convert the ADC input value to a divisor/scalar for the sine-wave lookup table(s) value to adjust the AC amplitude like this for a two phase servo controller.
https://forum.allaboutcircuits.com/...drature-phase-400hz-motor.187708/post-1746642
C:
/*
* micro-stepping  sinusoidal commutation for PWM using sine_foo or constant table
*/
int32_t phase_duty(volatile struct QEI_DATA * const phase, const double mag, const M_SPEED mode, const int32_t adj)
{
    if (mode == M_SLEW) {
        return phase_duty_table(phase, mag, adj);
    } else {
        phase->duty = (int32_t) (hpwm_mid_duty_f + (mag * sine_foo(phase)));

        if (phase->duty > hpwm_high_duty) {
            phase->duty = hpwm_high_duty;
        }
        if (phase->duty < hpwm_low_duty) {
            phase->duty = hpwm_low_duty;
        }
        return phase->duty;
    }
}
We take the pwm value returned from sine_foo(phase) an use the mag variable to scale to the needed peak voltage. A simple array table works for limited wave generation but I use something better to generate higher precision waves.

C:
/*
* generate one complete sine-wave cycle at one step per call
*/
static double sine_foo(volatile struct QEI_DATA * const phase)
{
    /* Increment the phase accumulator */
    phase->phaseAccumulator += phase->phaseIncrement;
    /* Limit the phase accumulator to 24 bits.
       The lower 16 bits are the fractional table
       index part, while the remaining 8 bits
       are the integer index into the waveform
       table.
     */
    phase->phaseAccumulator &= (256 * 65536) - 1;

    /* Calculate the table index. */
    uint32_t index = phase->phaseAccumulator >> 16;

    /* Get the table entry and the one
       directly following it.
     */
    double v_sin = table[index];
    double v_cos = table[(index + 64) & 255];
    double frac = 2.0f * PI * (double) (phase->phaseAccumulator & 65535) / 65536.0f / 256.0f;

    // fractional sin/cos
    double f_sin = frac;
    double f_cos = 1.0f - 0.5f * frac*frac;

    double result = v_sin * f_cos + v_cos*f_sin;

    if (++phase->phase_steps >= SAMPLERATE) { // reset per electrical rotation cycle
        phase->phase_steps = 0;
        phase->phaseAccumulator = 0;
    }
    phase->sin = result;
    return result;
}
https://namoseley.wordpress.com/2015/07/26/sincos-generation-using-table-lookup-and-iterpolation/
The table-lookup and interpolate method of signal generation is a powerful way to generate high-purity signals without resorting to complex approximations.With simple linear interpolation, a 256-entry table can produce sine and cosine waveforms with spurious responses that are around 90 dB below the carrier. At the expense of a few additional operations, spurious responses can be as low as -128 dBc by using circular interpolation.

The presented algorithms are also well suited to generate quadrature signals as both sine and cosine waveforms can be generated simultaneously.
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,225
I have no idea of how model trains are controlled.
A long time ago, like when I was a kid, I believe it was a mains to 20V transformer with a wiper on the secondary to select a number of turns and thus continuously vary the AC output voltage. The operation was similar to a rheostat.
 

Ian0

Joined Aug 7, 2020
9,809
A long time ago, like when I was a kid, I believe it was a mains to 20V transformer with a wiper on the secondary to select a number of turns and thus continuously vary the AC output voltage. The operation was similar to a rheostat.
I thought mine was a variac, but that would need a step-down transformer as well, so it might have had a tapped secondary with switches. It was followed by a selenium rectifier, as the train motors were all brushed DC motors.
 

BobTPH

Joined Jun 5, 2013
8,954
A long time ago, like when I was a kid, I believe it was a mains to 20V transformer with a wiper on the secondary to select a number of turns and thus continuously vary the AC output voltage. The operation was similar to a rheostat.
Yep, my Lionel transformer was the power supply for my early experiments with electricity, which mostly involved making wires glow red.
 

MrChips

Joined Oct 2, 2009
30,802
That is what I would suspect for AC.
DC speed control would be PWM?
Has anyone tried a dimmer switch (with step down transformer) for AC speed control?
 
Top