Max Simmonds Build Log

Wow, thanks @kvk! I’ve had far less thorough reviews from some companies I’ve worked at! You pointed out a few things I totally forgot to look at, and in some cases (capacitor footprints!) would have gone to copper, so thanks very much. I’ve addressed each point below:

R4 etc is 20mOhm, guess that is a typo

Yep - typo :man_facepalming: a copy and paste error on my part, I’ll change that to around 5 Ohms, it’ll be a placeholder anyway, but 20m is very misleading so I’ll change that.

D1 is zener. Replace with schottky. Zeners are sloooooow, so your gate boost turn of will dripple current through the parasitic cap

I think I chucked down any diode from the library - I should have spotted this is the symbol for a zenner! I was going to use something like this Buy Electronic Components Online - LCSC Electronics an SMD UF4007.

R20 is not nessesary, NRST has internal pullup. Normally when using external resistor is should be of 10k or less (avoid glitches)

I did not know that! I guess I should have guessed by the ‘N’ prefix, assuming that’s active low, and therefore has an internal pull up? Looking in the datasheet just now, it does state it has a permanent pull up, but could I have guessed by the ‘N’ prefix?

U2 has abs max 55V, but zener D7 is 56V type, so that won’t protect the module

D7 was there mainly so that the BLDC doesn’t generate a significant voltage to overcharge the battery. Let’s say that the battery is already at 55V (it’s maximum) and I’m going down a hill freewheeling, I wanted to ensure I don’t over charge the battery?
But you make a good point regarding it not saving the IC, however, the absolute max is 65V, so I think it should be okay.

U4 is is not a rail to rail opamp, so you cannot measure the stage current. Also, you need protection on that input, the motor currents can be negative. I think the MCP6c61 is a rail-to-rail opamp, though (https://ww1.microchip.com/downloads/en/DeviceDoc/20005367B.pdf). But I’m not sure what stage current is, is that an auto correct error and should be stall current?

You’re totally right about the negative current’s - I forgot entirely about that. I’ll add a schottky diode in series with the filter, to prevent any reverse current flow from the Opamp.

C23 is 0.47n, you need minimum 22uF for the buck converter
D8 should be schottky

DOH - again, copy paste error, but I would have taken that to copper! Thanks for pointing this out. I also haven’t yet spec’d the diode, I forgot about that. So I’ll find that too.

DS1 datasheet is hard to find, but AFAICS LED must be supplied from 5V. So no R34 and you need to drive it higher than 3.3V. The controller also seems to be needing 5V

DS1 is a placeholder for a random LCD module I have at home, but I will check that it’s 3v3 compatible, because I just assumed it would be, nice spot. The IO expander (U3) seems to be fine at 3v3.

A side comment. BLDC has more noise than FOC. The F030 can handle 3 phase FOC with the ST motor control library, so you could remove the need for the motor controller and hall sensors. Don’t know if you have other specific reasons for BLDC control. Maybe sourcing issues

Yeah this is totally a personal thing - I want to, at some point, write my own drivers for the F030, hence why I have the Hall effect sensors connected, but I don’t really need them for the control (since the driver will be doing that for me). But, to speed things up, I thought I’d start off with a driver. I can then probe the driver, see how it drives things, and replicate it in software at a later date, and, like you say, remove the driver and possibly the hall effect sensors if I go for FOC.

Thanks very much for the review!

If you got spare pins on your micro I would put some parallel to the SDA and SCL pin. I used it in a IIC design to get rid of the pullups resistors altogether. If you need more pullup you just change the software by make more pins pullup instead of tri-state.

you got very little headroom for the LCD backlight. I suggest you use a logic drive N-channel mosfet to avoid the Vce(on) of an NPN transistor. It also saves you the base resistor. Note that the Anode and Cathode of LCD displays are floating and normally not connected to GND or VCC. This means if you could connect them somewhere else. Personally I would have gone for a micro version with more pins. You could simplify the circuit by doing away with the bus extender and add more features like PWM the backlight and the contrast.

The voltage is too small, so a series diode won’t work

Add one accross the input, with a resistor in front. Then you divert current away from the opamp
Also, add a resistor network to offset bias the input to the opamp. Then you can actually measure negative currents

@kvk you’re, again, totally correct haha. I’ve gone for the following, what do you think?

(I don’t mind yet about measuring any negative currents, so I’ve kept it simple for the time being)

@Bikkel I agree with what you’re saying, the Vce will definatly reduce the available voltage, so, as per you suggestion, I’ve gone for a logic level FET. I kept a base resistor, just to ensure I don’t draw too much current from the IO expander, I also added a pull down to ensure it’s off when things are turning on:

Thanks a lot guys, I really appreciate it, it helps me learn a lot!

Looks good :slight_smile:
But you should change that opamp to a rail to rail one…

Are you sure its not rail to rail? I think the datasheet says it is but if it’s not I’ll change :laughing:

Sorry for the misunderstanding

It is indeed rail to rail :pray:

No worries! You helped me out a bunch, thanks a lot :slight_smile:

It’s been a few weeks now, and I thought I’d give a small update on what’s going on for those interested.

The eBike controller is now finished (!) and I’m about to send to JLC, check it out:


I’ve designed it so that I can develop the code for them STM32 with the LCD attached, then snap it off and place it on the handlebars as the speedo when it’s done. I can connect it to the controller via a harness, to the LCD board with only for wires, as the LCD board has an IO expander that’s controlled over I2C.

I’ve gone with push fit power terminals, to hopefully mitigate any broken solder joints due to vibrations, and also used some thermal jumpers on the FETs to an internal ground plane for heat dissipation. In terms of grounding, I split the plane up into power ground, digital ground, and analogue ground, with a star point:

I might pull back the analogue ground plane under the SD card, as that really ought not to be there, but other than that, I think it’s done!

Hey everyone,

I wanted to show my latest work on the ebike controller. The boards are in (from JLCPCB) along with the parts (LCSC). Unfortunately, they messaged me to say that one of the boards had a scratch, and therefore can’t be sent, they said they’d give me a voucher for the trouble, but I don’t believe they did.

!

Here’s a few photos of the board after I reflowed it. A couple of days ago I uploaded my first program to the STM32, and confirmed everything regarding the stm32 is working.

I’m now writing the I2C drivers, as I have an I2C expander before the LCD module. I’ll message here again when I have some more progress!

BTW, I got pretty frustrated with what JLC thought was reasonable voucher compensation for boards they made wrong for me (silkscreen order number slap bang on an enclosure front panel PCB when I had paid them to remove it). I explained that they had undervalued the additional shipping and tax that a reorder would cost, let alone the time delay cost. I gave a rough price breakdown of the real cost of those PCBs using the costs from that order and proposed a voucher value closer to the real cost. The service rep asked their manager and they granted the higher value voucher. Worth a try if the value they offered did not reflect the cost of fixing the issue.

Nice way to put the IET card to use!

Sorry, but is it really fair to complain about prototype PCBs, 2USD for 5 raw PCBs?

If you need higher quality and guarantees, spend 10x the price and get it from US or European suppliers

Lately I’ve been listening to the back catalog of the embedded.fm podcast. Just yesterday I heard an old episode with Bunnie Huang about low cost manufacturing in China, and how, at least according to my understanding of his argument, one effectively has to size the order with the assumption that the yield will be less than perfect.

I’m also convinced that you, also from the low cost manufacturer, can pay for enough QA to make the yield quite high.

It’s an interesting point, and one I hadn’t considered before. I always considered that their PCBs may be of lower quality, but I neglected to consider their service, too. I always found JLC to have reasonably good service, especially for the price. But I would still have preferred the scratched PCB to be sent, and let me decide whether it was too scratched.

Either way, I’m still happy with their service!

Hey everyone!

More updates, I’ve now written the I2C drivers, along with the LCD drivers. I’ve also written some code for the speedo, using one of the hall effect sensors to derive speed. I’ve written some code to generate a pwm signal (trailing edge) from the pot input.

I recently tested my buck (used to derive the 3v3 for the MCU from the 48V battery input) and I tested the 3 phase inverter I designed. I’m happy to say, everything seems to be in order! I was really happy to get the BLDC motor spinning, that was a good hit of dopamine. Here’s a video of the LCD and motor spinning:

I had a few issues along the way, one of which was me assuming (rather stupidly) that 4 bit LCD mode uses the lower nibble of the data bus, not the upper. Hence the need for the breadboard for the LCD. I also had to deadbug the I2C IO expander, as I assigned it an 18 pin package (instead of a 16) in KiCAD :man_facepalming:

Initially, the motor sounded horrendous, and was pulling a large amount of current under no load. I traced this down to me incorrectly silk screening the phases on my board. I simply swapped them around until it started working as expected. I also connected the pwm line from the stm32 to a pin that doesn’t have a timer output, which is required for the PWM mode, so I had to cut 2 traces and swap them with enamelled wire to fix this.

I’ve been keeping a list of issues here -Issues · maxsimmonds1337/EBIKE · GitHub and all the code here GitHub - maxsimmonds1337/Ebike_sw . The code is now in a stable (but not finished) state, so I’m now going through and making correct functions and header files etc.

I’m not sure how you guys do things, but I’m going to tag the committed kicad files as “v1.0” so I know what the original was, then correct all the issues I find, and finally resend the boards (V1.1) to be fab’d, rinse and repeat.

Does anyone else use git with KiCAD for hardware tracking?