I used this guide to hook up this 1.5v DC motor. The only difference is that I use a 3.3v controller instead of a 5v.
Everything works fine, but I am not sure I understand how to control the voltage with PWM. If I use 3.3/255 = 0.013, the 1.5 volts should be reached when I set the PWM pin to 115, but the motor's performance have not nearly reached max there and feels quite weak.
If I turn the pin up (which I probably shouldn't), the motor can spin much faster.
If I measure the voltage across the motor, when it is running, the voltage never exceeds 1.5, no matter how high I set the PWM pin.
My question is: How to I reach the maximum performance without risking destroying either motor or controller?
I'm going to guess the 3.3V power supply isn't "holding-up" under the load. Check that. You'll probably need a "bigger" power supply or a different voltage regulator.
If you're using the on-board 3.3V regulator, your motor is rated for almost 1/2 Amp and that's probably too much for it (depending on how much voltage you are dropping across the regulator). If the regulator is too hot to touch, that's a bad sign.
If I measure the voltage across the motor, when it is running, the voltage never exceeds 1.5, no matter how high I set the PWM pin
You can't reliably measure the PWM average with a digital multimeter.* But, you can (briefly) write a digital high (or 100% PWM) to see what you get. (An analog meter movement will give you a good average reading.)
If I use 3.3/255 = 0.013, the 1.5 volts should be reached when I set the PWM pin to 115,
Once you get it working properly you can boost that up a bit if you need to. You'll get a fraction of a volt drop across the transistor and although I didn't see a maximum voltage rating for the motor, there is a graph that goes up to 1.8V.
* P.S.
You can check your meter:
Disconnect the motor so there's (almost) no load.
Write a high or 100% PWM and read with the meter.
Write 50% PWM can read again.
...If it's stable and close to half of the DC reading you can use your meter to read PWM. You also can try something like 10% & 90% to see if the readings are linear.
I have now powered the motor with an external supply - a 5V 1A power bank. Everything works, but just as before, it doesn't really feel like it reaches it's full potential at 1.5V (PWM to 75), and it only starts at 0.8V (PWM 40).
Have you tried just connecting the motor direct to 1.5V e.g. an AA cell? Then you might get a better idea of what its "full potential" on 1.5V really is. From my (modelling) experience of small brushed motors if you want them going fast you nearly always run them on more than their nominal voltage.
You need to measure the current the motor needs, and compare to that under PWM.
With very low voltages like this the voltage drop across the free-wheel diode will make the speed/duty-cycle
curve decidedly non-linear as the motor might spends considerable proportion of its time at about -0.8V due
to the diode conducting, and might be spending a considerable amount of time just turning with no current
flow.
You should not expect the duty cycle response to be linear in slow-decay mode which is
what your setup is.
Synchronous rectification mode is the only nominally linear mode, and that takes 2 switching devices.
You would learn an awful lot from seeing the waveform across that motor - it isn't what you might think
due to the inductive kick-back, the diode, and the motor's (rotational) back-EMF.
Also the transistor may be struggling - is it a genuine 2N2222 part for instance? Try a 150 ohm
base resistor, not 270.