PreenFM Forum

PreenFM => PreenFM2 => Topic started by: zelea2 on October 31, 2017, 07:23:02 PM

Title: PreenFM2 SMD version
Post by: zelea2 on October 31, 2017, 07:23:02 PM
I'm in the process of redesigning a SMD version of PreenFM2.
The original goal of this design was probably to make it as easy as possible for people to solder their own kit.
Unfortunately  the Cerb40 module cannot be bought anymore so someone else has to solder the LQFP64.

I plan to build 5 pieces of this new design and make it as cheap as possible. The majority of components
will be bought from Aliexpress and the rest from Farnell.
- there will be just one PCB (15x10cm), no sockets.
- the 2 shift registers replaced with MCP23S17 (port expander)
- the 2 DACs replaced with PCM5102A
- OpAmp replaced with OPA2337
- extra MiniUSB socket placed on the main board
- all resistors and caps as SMD 0603
- cheap LCD 40x4 (no OLED)
I believe the total BOM will be well below 100$ (without the case)
The changes to the firmware to accomodate the new DAC and SPI-expander will be trivial and made with #ifdefs

Since I'm not comfortable with this KiCAD tool I have switched to OrCAD+Specctra and I'll make all design files available.
So far I've been able to export the PCB as GenCAD and after a lot of massaging I've now got an OrCAD PCB of the current
design with SMD passives. This way all the sizes and encoders/switches position will be preserved and I'll be able to use
the same cases.

Title: Re: PreenFM2 SMD version
Post by: Xavier on November 01, 2017, 09:52:47 AM
I'm in the process of redesigning a SMD version of PreenFM2.
The original goal of this design was probably to make it as easy as possible for people to solder their own kit.
Unfortunately  the Cerb40 module cannot be bought anymore so someone else has to solder the LQFP64.

Yes, the goal is to have a fun DIY synth project.
The preenF405 (CERB40 design adapted for the preenfm2) is and will remain available. So nobody has to solder the LQFP64 STM32 if they don't want to.

I don't get what you plan to sell ? the components ? Presoldered SMD preenfm2 ?

The move to OrCAD will move this project away from hobbyist.

Xavier






Title: Re: PreenFM2 SMD version
Post by: alien_brain on November 01, 2017, 05:17:29 PM
exciting!  can fit easier into euro rack maybe?   :)
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 01, 2017, 06:03:40 PM

I don't get what you plan to sell ? the components ? Presoldered SMD preenfm2 ?

The move to OrCAD will move this project away from hobbyist.


I completely agree with you about OrCAD. I'm also in favor of open source and I've been using Linux and free software for the past 20 years.
Unfortunately KiCAD is completely new for me while in OrCAD I've built over 100 boards. Initially I've planed to use KiCAD+Specctra but since
I need to migrate your design to KiCADv4 to maintain the schematic/PCB relation it's almost as much work as doing it from scratch.
Anyways I'll export the final PCB as GenCAD and MIN formats to make it as accessible as possible. Mentor PCAD can also load OrCAD files.

I am an electronics engineer by trade and I design ICs for a living; I also do some board design occasionally. I just want to experiment with
FM synthesis and since I already own too many keyboard synthesizers I was looking for a modular one. I've tried to get a Yamaha DX200 but
they are so rare and expensive. The PreenFM2 seems a very capable choice and I like this idea more than a VolcaFM. Music for me is just a
hobby and I'm in my 4th year of taking piano lessons ;-)

I couldn't get a PreenFM2 kit since they are out of stock so the next best thing is to build my own. Yesterday I've bough all the components
from Aliexpress, including the STM32 (5$) and the LCDs (5$), rotary encoders and switches and I've paid only 150$ for five kits. The prototype
PCBs will be some 40$ for 5pcs 2 layer 15x10cm size. So in the end the whole BOM for this project excluding the case will be less than 50$/unit.
That's how insanely cheap you can spend to build your own PreenFM2. The drawback is that now I have to wait 3-4 weeks for all the
component to arrive from China and probably as much time for the PCBs because I won't send it out before having all the components in
my hand to validate the footprints. For the cases I haven't decided yet - either I'll use a laser cut service and translucent green acrylic or I'll just
buy 1mm anodized aluminum sheets and machine it on my KosyA5 CNC router. I only plan to build these 5 units and maybe sell 3 or keep them all.

Attached are some pictures of my synth's room ...
Title: Re: PreenFM2 SMD version
Post by: alien_brain on November 01, 2017, 11:06:16 PM
id love one if youre taking pre orders!
Title: Re: PreenFM2 SMD version
Post by: SirPrimalform on November 07, 2017, 05:47:33 PM
While I have no need of another PreenFM2, I definitely want to see how the build comes out.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 15, 2017, 08:08:53 AM
I've got the majority of the components from China so today I've started the new schematic and PCB.
I still need to simulate the analog chain and probably remove/change some of the passive to make it comply with
the DAC's requirements and get a 0dBu (0.775V) signal output.

I'm documenting the progress here https://uglyduck.ath.cx/ep/archive/2017/11/PreenFM2_SMD_Version.html
I've listed there what I think are improvements from the current schematic.

The STM32 still has a lot of free pins. I could even get rid of the MCP23S17 and connect all the switches and encoders directly to the ARM uP.
I've added a second serial interface to connect maybe with another PreenFM2 or sync to other devices.

Before routing the PCB I'd like to ask the owners of this synth what do you miss in your PreenFM2?
What else can be added to make it better?

Some silly ideas:
- RGB LEDs or NeoPixels
- MIDI Through
- I2C OLED displays
- capacitive switches or sliders
- a stereo amplifier and socket for headphones


Title: Re: PreenFM2 SMD version
Post by: lokki on November 15, 2017, 10:02:25 AM
a stereo out jack and a dedicated headphone out would sure be great. other than that i am pretty happy. i would wish there were 4 outputs instead of only stereo so that you could route each instrument to another channel. but that is not gonna happen without adjusting quite a lot of the firmware and i am also not sure if the stm32 would support another stereo dac for the additional outs.

Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 15, 2017, 07:59:05 PM
i would wish there were 4 outputs instead of only stereo so that you could route each instrument to another channel. but that is not gonna happen without adjusting quite a lot of the firmware and i am also not sure if the stm32 would support another stereo dac for the additional outs.

The STM32F4 has two I2S interfaces and the PCM5102 are cheap and in small packages. One problem is the size of the 6.3mm sockets; there is not enough room for 4 of them so I'll have to switch to two 6.3mm stereo sockets instead.  But as you said the main problem is the firmware support.

Xavier, do you think the design I'm doing will be of any interest? I will publish a diff file with the changes of the git firmware (mainly using #ifdef's for the differences). Should I bother to ground one currently  unused STM32 pin so the future firmwares could distinguish between my hardware design and yours?
This will be just to report on the LCD that you are not using the correct firmware for the board and stop the code from running.
Title: Re: PreenFM2 SMD version
Post by: lokki on November 15, 2017, 10:26:29 PM
two stereo jacks would be awesome...
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 15, 2017, 10:41:35 PM
Xavier, do you think the design I'm doing will be of any interest?

This is a great project. But i'm not sure who the target is...
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 16, 2017, 06:47:06 PM
This is a great project. But i'm not sure who the target is...

The target are hobbyists who want a PreenFM2. After I proof the design someone else or a small company can manufacture the PCB with all the SMD components soldered and sell that as a kit. The end user will only have to solder the encoders, LCD, switches and sockets. With a stencil and a soldering oven and even a manual component place these PCBs can be manufactured very fast and cheap. Small companies who have automated pick and place machines can churn these boards in tens per hour.

The strength of this project is the firmware and the hundreds of man-hours you guys put in to develop it. So any derivative design should be able to reuse this firmware without too many modifications.

Keep in mind that a new Korg Volca FM can be bought for 150$. It can also load DX7 patches, has a case, MIDI and a sequencer. It doesn't have the same flexibility as the PreenFM2 though. The out of stock PreenFM2 kit and a metal case is 212E + 70E (approximately 330$) and this is one reason the Volca FM is selling so well.

I will build these SMD versions PreenFM2 mostly for myself and I'll solder them by hand. I do have a powerful stereo microscope and a steady hand so the only drawback is that it will probably take me an hour per board.

So I think you can use my build to proof a cheaper design, add a few new developments if you want and make the PreenFM2 more accessible and popular.

Title: Re: PreenFM2 SMD version
Post by: Xavier on November 17, 2017, 12:03:29 AM
The target are hobbyists who want a PreenFM2. After I proof the design someone else or a small company can manufacture the PCB with all the SMD components soldered and sell that as a kit. The end user will only have to solder the encoders, LCD, switches and sockets. With a stencil and a soldering oven and even a manual component place these PCBs can be manufactured very fast and cheap. Small companies who have automated pick and place machines can churn these boards in tens per hour.

The strength of this project is the firmware and the hundreds of man-hours you guys put in to develop it. So any derivative design should be able to reuse this firmware without too many modifications.

Keep in mind that a new Korg Volca FM can be bought for 150$. It can also load DX7 patches, has a case, MIDI and a sequencer. It doesn't have the same flexibility as the PreenFM2 though. The out of stock PreenFM2 kit and a metal case is 212E + 70E (approximately 330$) and this is one reason the Volca FM is selling so well.

I will build these SMD versions PreenFM2 mostly for myself and I'll solder them by hand. I do have a powerful stereo microscope and a steady hand so the only drawback is that it will probably take me an hour per board.

So I think you can use my build to proof a cheaper design, add a few new developments if you want and make the PreenFM2 more accessible and popular.

I was hopping you were not going to write that.
I really like the preenfm2 like it is today.  I would like it to remain a DIY project.

If like you say a small company manufacture the PCB, i would really feel robed.

Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 17, 2017, 07:07:20 AM
I really like the preenfm2 like it is today.  I would like it to remain a DIY project.
If like you say a small company manufacture the PCB, i would really feel robed.

From my point of view it is a completely DIY project - I'm even gone route my own PCB.
I have no intention getting into the commercial side of this, I'm earning enough money with my daytime job.
I will just proof my SMD version and make all the design files available.

But surely making it cheaper and available to more people can't be a bad thing for this project.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 17, 2017, 08:26:33 AM
a stereo out jack and a dedicated headphone out would sure be great. other than that i am pretty happy. i would wish there were 4 outputs instead of only stereo so that you could route each instrument to another channel. but that is not gonna happen without adjusting quite a lot of the firmware and i am also not sure if the stm32 would support another stereo dac for the additional outs.

I kind of have to decide between 4 outputs and headphones amp because the amp will be only stereo. Also if I will add a headphones amp it will be a Class D amplfier like the stereo 3W PAM8403.

If I go for 4 audio outputs then I'll have to replace the dual volume pot with digital control pots (let's say MCP42010) and replace the actual pot with another encoder. This extra encoder can control independently the volume on all the 4 output channels (so volume + pan times 2).

Anyone else thinks that having more audio outputs is a good idea? What other changes would you like to see in PreenFM2?
Title: Re: PreenFM2 SMD version
Post by: lokki on November 17, 2017, 09:54:29 AM
i think if you go down the route of the 42010 to control volume you might as well integrate that into the firmware as well, so that one can store the volume of patches. that way you would not need an extra encoder but control the volume via menus
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 17, 2017, 12:04:46 PM
Anyone else thinks that having more audio outputs is a good idea? What other changes would you like to see in PreenFM2?

More audio outputs is something many people asked.  Two 6.3mm stereo sockets sounds good to me.
If you change the pot to an encoder, would be great to have it clickable.
The preenfm2 has not enough buttons, so having a dedicated STM32 input for each of the 5 encoder clicks woud be usefull.

Also a Ground pins is missing near the Midi output header. Midi output cable are supposed to be shielded. Never had any problem with that but it cannot hurt adding that.

Pins available for a graphical display would be great. Parallel, i2c, spi something else ? I don't know much in graphical display.

I don't know if you modified the Connectors. P3 is important for the vcIn firmware.
The jumper JMP1 is totally useless. Must be connected in all situation.


Title: Re: PreenFM2 SMD version
Post by: alien_brain on November 17, 2017, 03:49:47 PM
how about a joystick?   ;)
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 18, 2017, 01:49:30 AM
i think if you go down the route of the 42010 to control volume you might as well integrate that into the firmware as well, so that one can store the volume of patches. that way you would not need an extra encoder but control the volume via menus

You can have both. The encoder changes the volume globally  and the software per channel / instrument. The MCP42010 can jump instantly to any set value. These will have to be bit-banged though because all the SPI/I2S interfaces are used.
I have started changing the schematic for 4 audio channels and I've ordered some more components. I will probably also put a TDA2822M as a headphones stereo amplifier. This is linear rather than class D because I don't want the extra switching noise and 500mW per channel is plenty for headphones.

I've changed all MIDI headers to 3 pins. The new encoder has a separate push switch connected. I will probably have to chose between separating the switches of all the other encoders and the P3 analog input header because I've started to run low on pins. Which one is better? Also is it worth having 4 separate LEDs  or more LEDs? If so maybe it's worth dropping a second MCP23S17 to handle the extra switches and LED outputs.

An even better option would be to replace the port expanders with a STM32F103 (only $1.20) running at 8MHz (internal RC clock) which can handle all the encoders, switches and LEDs independently and free a lot of extra pins in the STM32F4 and it can also keep track of the encoder values.
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 18, 2017, 12:13:29 PM
You can have both. The encoder changes the volume globally  and the software per channel / instrument. The MCP42010 can jump instantly to any set value. These will have to be bit-banged though because all the SPI/I2S interfaces are used.
I have started changing the schematic for 4 audio channels and I've ordered some more components. I will probably also put a TDA2822M as a headphones stereo amplifier. This is linear rather than class D because I don't want the extra switching noise and 500mW per channel is plenty for headphones.

Better DACs to allow 4 independants output is for me the most interesting part.
Is a headphones jack really usefull on the preenfm2 ?
I understand it is for sound modules with sequencer, but i wonder here if it's worth the effort here.
Where the jack will be ?

I've changed all MIDI headers to 3 pins. The new encoder has a separate push switch connected. I will probably have to chose between separating the switches of all the other encoders and the P3 analog input header because I've started to run low on pins. Which one is better? Also is it worth having 4 separate LEDs  or more LEDs? If so maybe it's worth dropping a second MCP23S17 to handle the extra switches and LED outputs.

Must be on the midi out only. If plugged on the midi in, there will be a shared ground with the midi device that sends midi.
Would be great to be mistake proof and having it just on the midi output.

Separate Leds or more leds are not usefull. The current ones are not even visible on all preenfm2 with metal case (the majority).
The 20x4 LCD is big enough to contain all usefull info.

I would prefer P3 than separated encoder switches. There might be a Eurorack version using them in the future (not from me).

An even better option would be to replace the port expanders with a STM32F103 (only $1.20) running at 8MHz (internal RC clock) which can handle all the encoders, switches and LEDs independently and free a lot of extra pins in the STM32F4 and it can also keep track of the encoder values.

Ouch... another firmware to write/maintain/flash... That would make the development and upgrade process much more complicated.
I think we should avoid that.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 19, 2017, 10:17:29 AM
I've made some progress and I have finished the schematic and footprints: https://uglyduck.ath.cx/ep/archive/2017/11/PreenFM2_SMD_Version.html
I will sit on it for a few more days waiting for input and then I'll route it and send it to manufacture.

Is a headphones jack really usefull on the preenfm2 ?
I understand it is for sound modules with sequencer, but i wonder here if it's worth the effort here.
Where the jack will be ?

Must be on the midi out only. If plugged on the midi in, there will be a shared ground with the midi device that sends midi.
Would be great to be mistake proof and having it just on the midi output.

Separate Leds or more leds are not usefull. The current ones are not even visible on all preenfm2 with metal case (the majority).
The 20x4 LCD is big enough to contain all usefull info.

I would prefer P3 than separated encoder switches. There might be a Eurorack version using them in the future (not from me).

Ouch... another firmware to write/maintain/flash... That would make the development and upgrade process much more complicated.

Ground is now on MIDI out only.

The headphones jack is squeezed on the back. For existing cases it's just a 6mm drill. Probably it's not at all useful as you say but the components can be left unsoldered. In the end it's just some board space.

With the separate STM32F1 we can have all of the above. I've started a quick CubeMX project and I will also write the code for it. It shouldn't take me more than an hour in Rowley Crossstudio. The uP is cheaper than the port expanders and is so much more flexible. It can store previous encoder values, it can send direction and several number of steps in one go.  It handles the global volume independently and encoder5 can be reused for data entry. Once I've decided on a data format there won't be any need to touch this firmware. How often do you modify the Encoders.cpp file from the PreenFM2 repository? The main board needs to be programmed with a bootloader first so using the same connector and the same programming tool this STM32F1 is flashed as well.

Now I have about 5 free pins on both STM32F4 and STM32F1 (I know I don't have to use them all) - any other usage?
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 19, 2017, 11:47:35 AM
I don't get exactly how the firmwares flashing will work.

Is there still the JMP3 to flash the STM32F4 through USB ?
Will the STM32F1 flashing require the ST-LINK programmer ?

Would be great to have also a led for the STM32F1, so that we can make it blink a little when the board is switched on to check it's correctly flashed and working.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 19, 2017, 07:27:13 PM
Is there still the JMP3 to flash the STM32F4 through USB ?
Will the STM32F1 flashing require the ST-LINK programmer ?

Would be great to have also a led for the STM32F1, so that we can make it blink a little when the board is switched on to check it's correctly flashed and working.

The jumper is J2 in my design.
Yes, the F4 can be programmed via USB or via SWD and F1 only via SWD.
I'll add a SMD LED to F1.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 20, 2017, 08:41:00 AM
I've placed all components manually and trial-routed the board with some huge vias. It has routed to 100% in less than a minute. For the final board I need to write all kind of rules, change widths, add planes etc.

If you spot any kind of error in the schematic or in the placement please let me know in the following days.
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 20, 2017, 09:52:22 AM

And you will solder all these SMD components by hand ?  :o
Title: Re: PreenFM2 SMD version
Post by: lokki on November 20, 2017, 02:32:15 PM
If you spot any kind of error in the schematic or in the placement please let me know in the following days.

i could not find a link to a schematic.
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 20, 2017, 03:26:35 PM
i could not find a link to a schematic.

Here:
https://uglyduck.ath.cx/ep/archive/2017/11/PreenFM2_SMD_Version.html
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 20, 2017, 04:15:54 PM
It works but i read from several olde display manual that we should avoid sending 3.3v data to a 5v powered display.
Do you think it would be better to convert the LCD_* lines to 5v (with a 5v inverter or anything else)?
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 20, 2017, 07:29:05 PM
And you will solder all these SMD components by hand ?  :o

Well, yes, about an hour of work per board. The LQFP and TSSOP chips have .5 and .65mm pitches and those are the easiest to solder. The secret is the flux that I'm using which is almost liquid and I'm using lots of it. I usually solder a whole row of pins with one touch of the iron. The most annoying parts are the 0603 because I'll have to pick each with the tweezer, solder one end, then apply flux to all passives, solder the other end and then come back and touch the first end again.

It works but i read from several olde display manual that we should avoid sending 3.3v data to a 5v powered display.
Do you think it would be better to convert the LCD_* lines to 5v (with a 5v inverter or anything else)?

There's no need for level translating the display. The HD44780 equivalent chip is itself powered at a lower voltage and we are not reading from the display so all the F4 connections to the display are outputs. It will only stress the F4 clamp diodes if we would need to interface an output signal which is higher than 3.6V.

Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 20, 2017, 08:11:05 PM
I have a few issues to clarify:

- what is the crystal you are using for the F4? I've put a 12MHz one, it needs to be a divisor of 48MHz because of the USB

- right now I've connected Channel1 Left/Right to one stereo jack AF1 and Channel2 Left/Right to AF2
  would it be better to have Channel1 connected to both AF1/AF2 tips and Channel2 connected to both AF1/AF2 rings? This second configuration will allow the use of only one PCM5102 and allow the use on mono cables as before.

- because I'm mixing the 2 lefts and the 2 rights for the headphones amp there is a small (-43dB) signal crosstalk between the before mentioned channels. If one doesn't want this if should replace R30/R38 with 0 ohm resistors and not solder the TDA2822M and its capacitors.

- a very important issue is the output sample frequency. The PCM5102 has its own PLL which locks to the WS signal. If the F4 isn't able to provide a constant stream of data this might be a problem. The F4 can also generate instead the system clock and send it to PCM5102 (just 2 extra pins of F4).

- there is an error between the desired sample rate and what the F4 can provide with the current crystal - for example instead of 44KHz the real audio frequency is 43.4KHz (an error of 1.35%). A 6% error is already a semitone. I haven't studied yet the current firmware - is the software able to compensate for this? what is the sampling rate you are using now?

- 24 and 32 bit samples need to be loaded in the SPI data register twice because that's only 16bit wide in I2S mode so the best way would be to DMA the data from the memory and let the MCU do something else in this time
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 20, 2017, 09:07:35 PM
I have a few issues to clarify:
- what is the crystal you are using for the F4? I've put a 12MHz one, it needs to be a divisor of 48MHz because of the USB

I also use a 12Mhz on the preenF405.

- right now I've connected Channel1 Left/Right to one stereo jack AF1 and Channel2 Left/Right to AF2
  would it be better to have Channel1 connected to both AF1/AF2 tips and Channel2 connected to both AF1/AF2 rings? This second configuration will allow the use of only one PCM5102 and allow the use on mono cables as before.

With solution1 mono cable will be possible but we'll need 2 PCM5102 even for 2 mono channels, right ?
So the difference is small, i don't have a strong opinion.

- because I'm mixing the 2 lefts and the 2 rights for the headphones amp there is a small (-43dB) signal crosstalk between the before mentioned channels. If one doesn't want this if should replace R30/R38 with 0 ohm resistors and not solder the TDA2822M and its capacitors.

- a very important issue is the output sample frequency. The PCM5102 has its own PLL which locks to the WS signal. If the F4 isn't able to provide a constant stream of data this might be a problem. The F4 can also generate instead the system clock and send it to PCM5102 (just 2 extra pins of F4).
- there is an error between the desired sample rate and what the F4 can provide with the current crystal - for example instead of 44KHz the real audio frequency is 43.4KHz (an error of 1.35%). A 6% error is already a semitone. I haven't studied yet the current firmware - is the software able to compensate for this? what is the sampling rate you are using now?

I don't know the PCM5102 so i don't know what is best for it.

Sample rates are here :
https://github.com/Ixox/preenfm2/blob/master/src/synth/Common.h#L43
I have a firmware (with o suffix) which overclock the F4 to 192Mhz which allows a higher sample rate.

With the current firmware the F4 has to feed 4 DACs so there is an interuption 4 times per sample to deal with DACs :
https://github.com/Ixox/preenfm2/blob/master/src/PreenFM_init.c#L182
https://github.com/Ixox/preenfm2/blob/master/src/PreenFM_irq.c#L164

This interuption takes the sample data from a 192 samples buffer that is constantly fill  by  synth.buildNewSampleBlock() :
https://github.com/Ixox/preenfm2/blob/master/src/PreenFM.cpp#L52



- 24 and 32 bit samples need to be loaded in the SPI data register twice because that's only 16bit wide in I2S mode so the best way would be to DMA the data from the memory and let the MCU do something else in this time

Yes, would be nice.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 21, 2017, 01:45:25 AM
With solution1 mono cable will be possible but we'll need 2 PCM5102 even for 2 mono channels, right ?
So the difference is small, i don't have a strong opinion.

True, but I'm leaning more to second case because then you can stop one PCM5102, save some power and CPU cycles.
The PCM5102 shuts the audio channel down when it detects several consecutive samples of 0 on both channels.
I'll probably split the SoftMute signal to each PCM5102 to have extra control. The XSMT input also monitors the 5V supply
through the R35/R37 divider and shuts the audio down when the 5V supply drops. This will prevent pop noises at power-down or power loss.

I don't know the PCM5102 so i don't know what is best for it.

Sample rates are here :
https://github.com/Ixox/preenfm2/blob/master/src/synth/Common.h#L43
I have a firmware (with o suffix) which overclock the F4 to 192Mhz which allows a higher sample rate.

Thanks for all the clarifications.

The reason I'd rather not send I2S MCK clocks to PCM5102 is to reduce EMI (those clocks are 256*fs so 11MHz traces on the board).
If the PCM5102 doesn't detect a system clock then it switches to its internal PLL which samples the BCK frequency and generates internal clocks for its miniDSP.
It is not clear from the documentation how wide is the capture range of this PLL but it will definitely work for standard sampling frequencies like 32, 44.1, 48KHz etc.

The F4 has its own PLL for the I2S interfaces and those can be configured with very fine grain to almost any sample rate with less than 1% error.

With the PCM5102 we don't need interrupts to send the samples; each time a couple of new samples become available we test the DMA in progress bit and if it's not set we just configure a new DMA transfer over all available samples. Another way of doing this is to get a interrupt at the end of a DMA transfer and set a new one with the available samples.

Is there any reason you've chosen a non standard sampling rate? Instead of 42031.52 (1142 ticks) you could have gone for 44117.65 with 1088 systicks.
In any case 42KHz is just 5% away from 44.1KHz so I expect the internal PCM5102 PLL to lock.
Title: Re: PreenFM2 SMD version
Post by: Xavier on November 22, 2017, 09:00:02 PM
Is there any reason you've chosen a non standard sampling rate? Instead of 42031.52 (1142 ticks) you could have gone for 44117.65 with 1088 systicks.
In any case 42KHz is just 5% away from 44.1KHz so I expect the internal PCM5102 PLL to lock.

It's only a performance reason.
With those sample rates, the CPU is close to 100% in worse case scenario (full polyphony with the most demanding FM algo, FX, arpeggiator..).
Title: Re: PreenFM2 SMD version
Post by: lokki on November 23, 2017, 09:00:18 AM
since a lot of cpu will be saved by the extra controller that handles encoder etc. 44.1khz seems doable...
Title: Re: PreenFM2 SMD version
Post by: norbim1 on November 23, 2017, 03:09:57 PM
Hi,
My fork on STM32F4Discovery uses 48k sampling rate with overclocked firmware. It runs without problem, since the I2S DMA also spares some CPU load. See my fork on Github. Actually the F4Discovery uses CS43L22 dac chip, but the I2S code part could be reused for PCM5102 too.

http://ixox.fr/forum/index.php?topic=63425.msg64969#msg64969
Title: PCB ready
Post by: zelea2 on November 23, 2017, 11:44:02 PM
I've added capacitors to all encoders and switches to eliminate contact debouncing in hardware rather than software. Also one pull-down resistor on pin D2 which is not currently used will be able to distinguish this board from stock (enable port D clock, input with pull-up D2, after 1ms read pin2: 1-stock 0-mine, disable port D clock).

The board is now finished and I've published the Gerbers and all the design files. I'll send it tomorrow to be manufactured and maybe I'll even get a black Friday deal.

I can now turn my attention to firmware until the boards arrive in 3 weeks time.
Title: Re: PreenFM2 SMD version
Post by: lokki on November 24, 2017, 10:51:01 AM
great! please post all updates...
one question, when one would want to build this, without smd soldering experience, would you sell preassembled boards with the stm32's on and burned firmware for the stm32f1? or what is the plan?

cheers
Title: Re: PreenFM2 SMD version
Post by: zelea2 on November 24, 2017, 05:44:27 PM
one question, when one would want to build this, without smd soldering experience, would you sell preassembled boards with the stm32's on and burned firmware for the stm32f1? or what is the plan?

I might sell 1-3 of the 5 units I'll build presuming everything works fine and I haven't made any mistakes but don't count on me for getting into manufacturing these units.

People are soldering SMD parts all the time, it's not an impossible task. These are actually easy to solder SMD packages.
My only goal is to make this SMD version work and then publish all the files and firmware modifications so anyone can build them (or even start selling pre-soldered kits if they want to) .
Title: Re: PCB ready
Post by: zelea2 on November 24, 2017, 08:36:12 PM
I'll send it tomorrow to be manufactured and maybe I'll even get a black Friday deal.

I did get an great deal. 37$ delivered for 10 PCB (green mask only). I could have got a stainless steel stencil for just another 13$. Crazy prices from EasyEDA.
Title: Re: PreenFM2 SMD version
Post by: lokki on November 24, 2017, 10:47:49 PM
one question, when one would want to build this, without smd soldering experience, would you sell preassembled boards with the stm32's on and burned firmware for the stm32f1? or what is the plan?

I might sell 1-3 of the 5 units I'll build presuming everything works fine and I haven't made any mistakes but don't count on me for getting into manufacturing these units.

People are soldering SMD parts all the time, it's not an impossible task. These are actually easy to solder SMD packages.
My only goal is to make this SMD version work and then publish all the files and firmware modifications so anyone can build them (or even start selling pre-soldered kits if they want to) .

ok, well if this works out ok, count me in!
Title: Re: PreenFM2 SMD version
Post by: matrix12x on November 24, 2017, 11:13:27 PM
Count me in as well.
Title: Re: PreenFM2 SMD version - F1 firmware
Post by: zelea2 on November 25, 2017, 02:35:20 AM
I have finished a rough version of the STM32F103 firmware
If anyone wants to have a look it's here http://uglyduck.ath.cx/PreenFM2_SMD/SurfaceControl_F103.tar.gz

The processor sleeps most of the time, it's only awaken by the systick interrupt every milisecond or by a surface event or a SPI command. I have 5 encoders + 5 encoder switches + 7 switches so that's 17 and the processor only has 16 EXTI lines. So switch 6 has to be separately scanned every milisecond.

At the start a LED is flashed 6 times so you can see the processor is alive. A second LED near encoder5 shows the function of this encoder - if it's lit then the encoder acts as a global volume knob and doesn't generate a surface event. The volume is adjusted by the F1 alone.

Every time a surface event occurs the F1 raises an interrupt line. The main processor can read the entire surface status with two 16bit SPI transfers whenever it has time. Each encoder can memorize up to 7 steps. A second SPI interface controls the digital potentiometers. Both SPIs are at 2Mbit/s which is maximum for its internal 8MHz clock. All SPI transfers are handled by the DMA.

One command also allows the F4 just to read the switches status in real time (maybe useful to detect long-presses). I have so far 7 commands from F4 that I handle. Is there anything missing?

The volume scale is logarithmic. The F1 initializes the number of volume steps with a default value. The F4 can also change the number of steps. Each of the 4 audio channels have a maximum volume fixed at 255 at the start. The F4 can also change the top value for each channel at any time.  The global volume acts as a fraction of this top volume value.

I've split the flash memory in half and I'm using the last part to store some non-volatile local variables. So far I only have the current volume position and the volume number of steps.

For now I'm relying on the external caps for the debouncing but what I plan to do is to use all the available 4 timers in a round robin scheme  to start a one-shot count when a switch/encoder is pressed and ignore any following presses until the timers elapse. With 4 timers I can keep track of 4 simultaneously pressed switches/encoders.

Any suggestions are welcomed.
Title: Re: PreenFM2 SMD version - F1 firmware
Post by: zelea2 on November 29, 2017, 01:05:26 AM
I plan to use all the available 4 timers in a round robin scheme  to start a one-shot count when a switch/encoder is pressed and ignore any following presses until the timers elapse. With 4 timers I can keep track of 4 simultaneously pressed switches/encoders.

I've added the timer filtering and 2 new commands to interrogate the F1 firmware date/version and to get a configuration word which says how many audio channels are soldered on the board. Presumably the F1 will be only programmed once when the board is soldered so it makes sense to hold this configuration word.

The code can be compiled now with both CrossStudio and a makefile. I've briefly tested the code on one of those chinese STM32F103 boards and the surface controller code seems to work fine.
Title: Re: PCB ready
Post by: zelea2 on January 07, 2018, 08:59:08 AM
I did get an great deal. 37$ delivered for 10 PCB (green mask only). I could have got a stainless steel stencil for just another 13$. Crazy prices from EasyEDA.

After a quiet period I'm back. My boards arrived in the post 42 days after I've ordered them. I was hoping to get them before XMAS so I can do some work over the break but no luck. It took EasyEDA 25 days to manufacture them and another 17 days to get them shipped. This was the first time I've used them and I am not very happy about this delay. In the past I've used "ITEAD Studio" "Seeed Studio" and "Dirty PCBs" which were also cheap and I've received boards in about 3 weeks time instead of 6. This time I've cheapened  and got EasyEDA  as the first entry from  http://pcbshopper.com . Lesson learned not to use them again unless I don't care about the delivery time.

Anyways I have 10pcs now and by the end of this week I plan to solder and run my test programs on one. To test the functionality I will just use 4 encoders to generate sine waves with all the piano notes on all 4 output channels.
Title: Re: PCB ready
Post by: zelea2 on January 13, 2018, 06:57:35 AM
[Anyways I have 10pcs now and by the end of this week I plan to solder and run my test programs on one.

I've managed to solder 2 boards. On my first try each processor was working on the other board. Quickly traced this to a short and some passives soldered to one end only. Now I have both uP blinking LEDs on both boards but I haven't done any more testing.

Unfortunately I've over-estimated my soldering. It took me a total 6 hours to solder these 2 board (so 3h/board).
All the ICs went very fast, probably an hour for both boards. The switches, encoders and electrolytic  caps another half an hour. What's killing the rest of the time are the passives. There are 144 passives per board with 2 ends each ;-)  and you have to pay attention to all the different values. That comes to about 1 minute per passive.

With this time consuming experience in mind I probably won't solder anymore boards any time soon. I'll have to forget about all those 0603's first. For my future testing I won't need any more anyways.

The good news is that I haven't found anything wrong (yet) with my design like unmatched footprints or schematic faults. The next few days I'll prove all the audio chain and then I'll be ready to install the real software.

This is how I've spent my Friday evening and night ...
Title: Re: PreenFM2 SMD version
Post by: zelea2 on January 16, 2018, 08:31:59 AM
I haven't done any more testing but I've taken some pictures of the soldered boards. A few things I've noticed: the buttons caps that I have are way too low (they dont reach the screen base). Only one DIN connector fits comfortably at the back; a second will have to have its pins trimmed to fit in the back. but I have 2 more so I think I'll put all the DIN5 connectors on the sides.
The boards are still covered in flux; I haven't cleaned them yet.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on January 19, 2018, 07:56:38 AM
After another 10 hours of coding I want to report some good progress:

I've got the inter processor communication working. This was tricky because the F4 is the SPI master and the F1 raises an interrupt wire when any of the switches or encoders change state. For the F4 this transfer is transparent, everything is done by the DMA at both ends and after the 32bit transfer it can process the new input whenever it likes. There are also some commands which change parameters like the max volume and interrogation commands like the firmware version. So the F1 must start a DMA receive but if a key/encoder is pressed it must abort the current DMA (because the first word is already loaded in the SPI register) and start a new one with the new info. This allows the information exchange in just one 32bit transfer.

My encoders can send +/- 7 steps but regardless of how fast I turn them the max was +/- 2 steps. Also the detection algorithm for the encoders should be improved (now I'm basing this on just one sample) because I get the occasional step in the opposite direction.

Also my note generation works. I get sine waves on all outputs but I have a horrible super-imposed noise in my headphone amplifier. I have to admit that I haven't put a scope yet on my boards and my only detection method was a pair of headphones. I can also hear the microcontroller running in my headphones so this is bad. I hope that the only culprit is the headphones amp which was a bit of an afterthought. This is powered by the general 5V line and connected to the digital ground (instead of the analog ground as the rest of the audio path) while it has a 39db gain! I might have to scrap this and use only the jack outputs.

The wave generation is using 48KHz sample rate on all 4 channels and all transfers are DMA. I get a half way transfer interrupt and I'm filling the other half of the buffer based on a precomputed sine wave table and the desired frequency.

What's not working is the digital volume (haven't investigated why), haven't checked the purity of the sine waves with a scope and I get a very rare hangup of the surface processor so there's still a bug in there. Another bug is also lurking in my F4 code which manifest itself only when I'm compiling as a release, the debug version works fine. So programming still required.

All in all I'm very pleased so far because all the audio chains are working at least up the output of the DACs and the processor spends most of the time sleeping in the main loop.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on January 19, 2018, 06:46:38 PM
I can confirm that there is no noise at all on the jack outputs; I'll make some scope captures during the weekend.

The headphones amplifier needs a redesign. The idea of mixing 2 channels and then amplifying it almost 100 times with no proper dedicated supply is bad. Probably the best way is to choose only 2 channels instead of 4 and reduce the voltage gain considerably. Other option is to use a cheap LM324 to mix them and then use another phones amplifier IC and use a dedicated power rail for it.

For the current boards the headphones schematic is compromised and I'll have to desolder that part of the circuit.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on January 20, 2018, 05:18:53 AM
More problems fixed:

I've solved the digital volume and now it works beautifully with a logarithmic scale. I was sending the potentiometer bytes in the wrong order.

One of the audio channels was bearly audible. I've traced that to 2 mislabeled references of 2 caps. I've switched those and everything is fine.

I'm thinking of redesigning the headphones amplifier for a further revision. Separate 78L05 supply, MC33204 OpAmps (couldn't use LM324 because it's not rait-to rail) for mixing the 4 channels and provide proper separation and LM4880 as 200mW/channel amplifier. I've already done the simulation.

I haven't tested MIDI yet but I don't expect any surprises there.

I'm still struggling with the encoders. I can't get rid of that extra step in the wrong direction when they are turned fast. If I mask the inputs longer than 15ms then I'm missing steps, shorter and I have the jump backwards. The question is do I have some particularly noisy encoders or are my algorithms bad? Right now I'm triggering on the falling edge of one input, masking further interrupts with times and I'm examining the state of the second input for the last 15ms. How is your experience with the encoders on the current design? The switches on the other hand are perfectly debounced.
Title: Re: PreenFM2 SMD version
Post by: alien_brain on January 20, 2018, 07:27:08 PM
all pretty exciting!  hey do you think you could find out why the white oleds are not shining as bright when swapped in and do the necessary changes?  im very excited to use one of these when you have them ready.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on January 21, 2018, 09:39:01 AM
hey do you think you could find out why the white oleds are not shining as bright when swapped in and do the necessary changes?

OLEDs are a vanity thing, I'm just interested in functionality. Yellow ones are always much brighter than the white ones - it's a construction feature. All the ones I'm building use plain green-yellowinsh LED backlight. The difference is the price 5$ compared to 35$. The screen can be swapped with ease anyways.
Title: Re: PreenFM2 SMD version
Post by: alien_brain on January 21, 2018, 02:11:46 PM
golly thanks for that i guess.  btw white oleds are just as bright.  im not a technical guy but my tech has white oleds in his yamaha fm synths like tx802 and tx81z that are just as bright as any other color i have seen anywhere.  so...  nows your chance to be vain i guess.  whats wrong with white oleds?  it would certainly make a statement.  what a pity that you dont care.  oh well,  i guess the only thing your design has that i want is 4 outputs.  but even then im not sure that means very much unless you cant afford a second synth...
Title: Re: PreenFM2 SMD version
Post by: Xavier on January 21, 2018, 02:25:26 PM

Impressive soldering skills !!!  :o
Nice pictures....
Title: Re: PreenFM2 SMD version
Post by: matrix12x on January 22, 2018, 01:18:47 AM
I'm really excited by the progress.
Title: Re: PreenFM2 SMD version
Post by: zelea2 on January 26, 2018, 01:57:48 AM
I have updated my project's page (https://uglyduck.ath.cx/ep/archive/2017/11/PreenFM2_SMD_Version.html) with real oscilloscope captures from the DAC and the line output if anyone is interested.

I've also redesigned the headphones amplifier for an eventual future version.

The PCM5102 performs very well and with its dynamic range of 112dB it has effectively 19 bits of precision (so I'm sending 24bits in 32bit frames per channel). If we compare this with the MCP4922 we can already see a big improvement. The 12 bits of the MCP4922 have a typical cumulative nonlinear error of +/-2LSb but this can go up to +/-12LSb. Then there is an abrupt nonlinearity when the 2 DACs are connected together; even with the  1% tolerance for the 1.8K resistor, 1% is equivalent with another resistor of 180K injecting current into the node, and that's almost as the entire contribution of the second DAC via the 155K resistor.