Simulate AC signal

Is it possible to simulate an AC signal (6.2 kHz in my case) using two outputs, which alternate HIGH/LOW 180 degrees out of phase with each other? I believe these outputs would need to be fed to some transistors to handle switching of the supply and ground leads to the circuit, but I’m struggling with whether this is possible with the Photon.

I believe I could also accomplish this using a fixed supply voltage and an H-Bridge controlled by the output of the tone() function; however, I would like to know if the first (above) mentioned method is feasible, since it may result in fewer required components.

I’m trying to transmit an RF signal using a simple wire loop. DC pulses actually work, but as might be expected, I’m getting extremely poor range.

I’m open to other suggestions if I’m overlooking an obvious solution. I’m just getting into this as a hobby…

1 Like

It’s not entirely clear what you’re trying to do. Do you want a square wave or a sine wave? Are you trying to make a wave that’s symmetrical about 0 volts (like AC line voltage is)? The tone function by itself can generate a 6.2 kHz square wave, if that’s all you need.

After Edit: Looking at you post again, are you wanting to hook up this loop antenna between the two outputs that you want 180 degrees apart? To answer your first question, I do believe it’s possible to set one pin to HIGH and another pin to LOW simultaneously by writing to the BSSR register directly. The low 16 bits of this register are used to set a particular pin HIGH, and the high 16 bits are used to set a pin LOW. For example, if you want to have D0 Low at the same time D1 is HIGH, then reverse those, you could do this:

GPIOB -> BSSR = (1<<6) | (1<<23);  //that's equal to 8388672
// some delay here
GPIOB -> BSSR = (1<<7) | (1<<22);  //that's equal to 4194432

These numbers come from the fact that D1 is attached to PB6 and D0 is PB7 (7 + 16 = 23). This comes from the reference here.

3 Likes

With a push in the right direction, I was able to get this to work. I ended up using the pinSetFast() and pinResetFast() methods instead of the GPIO -> BSSR method.

I’m emulating an AC signal by wiring the outputs of D0 and D1 through a wire and sending pulses 180 deg out of phase to these pins at the desired frequency.

Is there a max current output for these pins that I could use to calculate an appropriate resistor value? The only current ratings I was able to find seemed to be related to total power and not for individual pins. Will I burn out the pins if I simply connected a wire from D0 directly to D1?

-Carey

The max output current or current to sink is 20mA - beyond that you risk frazzling your pin.