2 phase synthesised sinewave generator for synchronous motor drive

This whole epsidoe falls in the "pay attention to what you're doing" category...

I forgot to comment out the #define... line that sets frequency to 60Hz during initialization and recompile. All fine now.
Ah yes, good spot. I had the thought that running at the below-spec voltage may have been causing the writes to the non-volatile to fail, but glad there was a simple solution.
 
Last edited:
Hi Rich, What would need to be done to use a rotary encoder to control frequency up and down? I've used on on the SG4 and it's nice to have a single hole on the front panel when using the OLED.
I've had a glance at the rotary encoder add-on for the SG4, I see no reason why this could not be used here too, as it converts the rotary encoder movement to a series of pulses to emulate UP and DOWN button presses. The only issue I can foresee is, as the button inputs are active-low with the on-chip pull-ups enabled, then depending on the polarity of the rotary encoder PCB outputs, it may require the tweaking of the button polarity and disabling of the pull-ups in firmware. If you have the part, I'd give it a try as is.
 
I should have mentioned that I had already tried the SG4 part and it didn't work. I think I understand about disabling the pullups in the firmware but don't understand "tweaking the button polarity"
Looking at the SG4 schematic, the buttons are similarly active low (one side connected to ground, the other to the input pins), so the polarity won't need modifying, and very probably you won't have to disable the pull-ups either.
I can't find any connection details for the rotary encoder PCB, but I'm guessing its ground, +5v, and signals to connect to the UP and DOWN button inputs. So these should be connected to GND, 5v/VCC, and the header pins closest to the 'BUTTONS' label for pins A1 and A2.
If this is all OK, can you connect a 'scope, or even a multimeter, to the A1 or A2 input, and see if you get any transitions when slowly rotating the encoder?
 
Member
Joined 2014
Paid Member
Thanks, Rich. that was helpful. I used the 'scope and found pulses were only 4ms so I had to reduce the de-bounce delay (I used 3ms) and also need to remove firmware pullup on A1 and A2 or else pulses weren't consistently recognized. Now it's working consistently with the rotary encoder designed for SG4.
 
Thanks, Rich. that was helpful. I used the 'scope and found pulses were only 4ms so I had to reduce the de-bounce delay (I used 3ms) and also need to remove firmware pullup on A1 and A2 or else pulses weren't consistently recognized. Now it's working consistently with the rotary encoder designed for SG4.
That sounds brilliant, I'm a little envious now.
You nicely pre-empted my next question about the pulse width and possible need to reduce the software debounce delay, so that's good to know.
What I'll probably do is add a 'ROTARY' option into the firmware so that this becomes a new feature, once done maybe you could verify it for me.
 
Member
Joined 2014
Paid Member
That sounds brilliant, I'm a little envious now.
You nicely pre-empted my next question about the pulse width and possible need to reduce the software debounce delay, so that's good to know.
What I'll probably do is add a 'ROTARY' option into the firmware so that this becomes a new feature, once done maybe you could verify it for me.
Yes, I'd be glad to verify that the new option works. For what it's worth, I think there's a debounce capacitor on the extra board that Bill Carlin made to accommodate the rotary encoder (which is why the pulse is so small)
 
Hi Rich, this is a very nice project. However, I can't find the latest source code. Am I too stupid or did you remove it from the public. Cheers, Lars
Thanks. Please send me a message with your target set-up so I can make sure you have the most relevant version, as there are (always) on-going developments.

Talking of which, having fielded various requests from a couple of members, there are a few more features now included:

- Selectable amplitude reduction after a chosen delay. This has been added to better support 3-phase BLDC motors (in this particular case using the same amplifier board as suggested on the SG4 thread). Example waveform (with Soft-Start enabled) below. The supported final amplitudes are from 95% to 75% full-scale in 5% increments.

ref_ampred_ss.png


- Rotary encoder support. Currently support is included for the SG4-style rotary encoder PCB which mimics the pressing of up and down buttons. However in the pipeline I have added direct support for rotary encoders with no additional PCB/components (this firmware will be available once I've implemented a delayed saving of the frequency so the rotary encoder does not flood the EEPROM with writes).

I will update the documents and GitHub archive when completed.
 
If you only want 2 phase, it's done for you -
https://www.ebay.co.uk/itm/112980558519?hash=item1a4e2a82b7:g:XqwAAOSw8fRbPraj

3 or more phase, you have to produce your own.

Personally I would have a look at the DRV8825 which has 1/32 micro stepping with current chopping at 250KHz - supports two phases and I've used it with a NEMA planetary drive stepper for focusing telescopes with 5+Kg of camera equipment mounted at the back. You could experiment with parallel 6 of them and get 12 poles, pre-step each to provide an offset and you then have a 0.00156º step if I have my sums correctly. Thus more accurate than a Thorens TD124 DD 12 pole motor wow/flutter.

However it's not a free lunch - the NEMA servos whine audibly as they move. Making that quiet 12 pole motor would be the hard bit.
 
Hi Rich
I have the v1.0 pcb running ok and would like to upgrade to the oled display and rotary enc.
Would this be possible with my version 1.0 pcb or would I need to get the new version pcb?
Yes v1.0 boards should be no problem, the v1.1 was because I was getting some more boards made, so did a couple of tweaks mostly aimed at more neatly supporting the 3rd phase for a 3-phase setup, plus adding a small prototype area, but both are suitable for any setup.

The main thing you will have to do is extend the pins in a few placed in order to connect the OLED display, as shown in the latest build guide in post 1 and and on my GitHub page linked there.

The latest firmware has native rotary encoder support, I haven't yet added the write delay for the EEPROM as mentioned a couple of posts above, but it will work fine nontheless, send me a message when you're ready.
 
boards ready!

Received the boards and made one up, the photos below show a version with screw terminal outputs, another with a 3.5mm stereo socket (mounted on the Arduino), plus an underside view with the Bluetooth module mounted.

The additional filtering on the output gives good attenuation of the PWM harmonics, with only a tiny additional attenuation in the pass-band, with the simulated AC response with and without the additional filter shown below. The sinewave outputs and spectrum are shown in the next picture.

Also included here are the updated schematic and Arduino code, please see the first post for details of uploading and runnin for the first time.

If anyone wants to make one up, I have some spare boards that I'm happy to send out at cost ($1.50) + postage, or the Gerbers are attached here also.

- Rich