Hey there, I've mainly used Arduinos and Pi's in previous projects and I'm working with the Bela Mini for the first time. I see that you can run it directly off of a simple LiPo, but haven't found a clear answer online to whether the battery can also be recharged directly through the board. Can I just power it via USB and that will recharge the battery? Thanks!
Recharging LiPo Battery?
- Edited
I think battery charging should work, though I don't have a lipo to test right now. The steps to be followed should be:
- connect a 10k resistor between P2.15 and P2.16
- connect the battery to P2.14 (+) and P2.15 (-)
- connect the PB via USB
- run i2cget -y -f 0 0x24 0x03
to check the PMIC charging status via I2C
- output should be 0b001000
- see PMIC datasheet for more info: http://www.ti.com/lit/ds/symlink/tps65217.pdf
- there might be a flag somewhere in the PMIC registers that needs to be set with an i2cset
command
Awesome thanks giuliomoro! Just getting back to this now post-holidays.
Looking at the pinout it looks like P2.15 is the GND, so battery should be flipped from what you wrote, correct? ( P2.14(+) and P2.15(-) ). The 10k resistor remains between GND (P2.15) and BAT Temp (P2.16) if I'm understanding correctly.
I've got some 10k resistors arriving tomorrow, so will try it then!
yes well spotted, I am amending the post above to prevent further confusion.
- Edited
Ok just tried this out, when I hook up the resistor and battery, the board doesn't boot. I plugged it into USB and it booted, but when I ran the i2cget it returned 0x10. I unplugged the USB and it kept running though.
Edit: I managed to get it to boot, just had to get a probe in between the boards to hit the power button. I guess I'll just have to plug in a USB to boot and then unplug.
Reading through the Beagleboard forums it seems that there is indeed a flag that needs to be set, but no word on what exactly that is!
m-coyle Edit: I managed to get it to boot, just had to get a probe in between the boards to hit the power button. I guess I'll just have to plug in a USB to boot and then unplug.
The pins for the button are available on the PB header, so you can just put a switch there. See https://github.com/BelaPlatform/Bela/wiki/Powering-Bela-with-an-external-power-source#using-lipo-batteries-with-bela-mini
m-coyle indeed a flag that needs to be set, but no word on what exactly that is!
Check out the charger configuration registers in the datasheet. At a quick look, CHGCONFIG1 seems to be the one you want to write to.
Ok yes it definitely looks like that! I have to set bit 0 of 0x04 to be 1b, and the device address is 0x24.
Now this is my first time dealing with I2C as well, so I've done some research and it looks like the command should be:
i2cset -y 0 0x24 0x04 ā¦. and then Iām not sure? Maybe 0x1b? Is that first 0 referencing the bit number?
Thanks!
Ok after more research, I think I understand!
From: i2cget -y -f 0 0x24 0x03
I get: 0x08 (not sure why this has now changed, I think maybe the 10k resistor wasn't placed properly earlier)
Which is the same as: 0x0001000 (which I think is what you said it should be, which means it's charging?)
From: i2cget -y -f 0 0x24 0x04
I get: 0xb1
Which is the same as: 0x10110001
Since the last (0th) bit is 1, it means the charge is enabled (so I guess it was already enabled?). If it was disabled it would have read 0xb0 (0x10110000)?
I t
m-coyle 0x0001000
0b00001000
That seem to mean it's charging.
m-coyle 0x10110001
0b10110001
.
m-coyle Since the last (0th) bit is 1, it means the charge is enabled (so I guess it was already enabled?). If it was disabled it would have read 0xb0
That seem to me to be right.
So, I guess the question is: is it charging? You can test that by placing a multimeter in the ampere setting in series with the battery and making sure the current is going towards the battery and not towards the board. If you don't see the charging happening, you could try to toggle bit 3 "RESET" of CHGCONFIG1
:
Charger reset
0b = Inactive
1b = Reset active. This bit must be set and then reset via the
serial interface to restart the charge algorithm.
So try to set the bit to 1 and then back to 0. If I read the docs for i2cset
correctly, this should do it:
i2cset -y -f 0 -m 0x8 -r 0x24 0x04 0x08 b
i2cset -y -f 0 -m 0x8 -r 0x24 0x04 0x0 b
the -m 0x8
(mask) parameter makes sure that you are only actually changing bit number 3, while the rest of the value is left untouched (under the assumption that reads and writes are symmetrical, which is true for this specific register).
See if after this operation you get either the battery charging or some changes in the CHGCONFIGx registers.
Amazing thanks giuliomoro! It does indeed look like it's charging! I've put together the software too now, and just went to take it off of USB power, and suddenly the sound is all distorted! I've got my block size as large as possible, and I've stripped down the software to make sure it's not because the chip is overrunning, I suppose it may just not be getting enough power, since I'm running a lot right off of the board.
A few thoughts I'm going to try:
- run the battery through an Adafruit Powerboost, so that the board is actually receiving 5V
- run the amplifier (PAM8302) straight off of the battery to reduce the load running through the board
I notice the registers for the PMIC also contain flags for the USB power limit, and the AC power limit, but nothing for battery power limit. Any thoughts on a way to increase that?
Thanks!
m-coyle and suddenly the sound is all distorted!
Is the sound coming out of the board distorted? My guess is that the output of the board will be fine, but the power amp is where the distortion happens.
Have a look at the pam8302 datasheet,
You will have seen in the datasheet fot the pma8302: the output power decreases a lot with the power supply voltage, so that with a 3.7V input you get down to about 1W. You could try reducing the gain on the power amp to confirm that this is the case: reducing the gain should reduce the distortion.
In this sense,
m-coyle run the battery through an Adafruit Powerboost, so that the board is actually receiving 5V
seems like a good option, while I don't think that
m-coyle - run the amplifier (PAM8302) straight off of the battery to reduce the load running through the board
would help.
m-coyle nothing for battery power limit. Any thoughts on a way to increase that?
I guess thar value may be hardwired. However, I don't think that increasing it would help in thie situation.
The extra power supply helped a lot, but not all the way, I'm running both the board and the amplifier straight from the Powerboost now. I've also confirmed that the problem isn't on the amp/output side. I can run sine waves through that no problem and they're nice and clear and loud. It must be on the input side.
On the input I have just a piezo coming in, but I haven't put any protection on it (as it worked before, undistorted, without protection). I've now put a 220k resistor in parallel with the piezo and it compresses the signal a bit, which is great, but still is distorted. A bigger piezo produces a lot more distortion, so I'm thinking I'll have to grab the smallest piezo I have, and also maybe use a smaller resistor to sap more of the current. Maybe a resistor in series as well? Perhaps the voltage is just too high and it's clipping?
Right, so this should be independent from whether you are using the battery or the USB PSU, right?
To find out if the piezos are clipping, simply look at the input signals on the Bela scope (there are examples both for C++ and PureData to use it). You may have to change the scope setting to better visualize the signals (e.g.: trigger mode Normal, triggering level 0.1, or similar).
Are the piezos going into the audio inputs?
If so, you can reduce the PGA (programmable gain amplifier) for the channels. If that is not sufficient, you can also reduce the ADC level. These settings are available from the project settings tab in the Bela IDE.
If, instead, you are connecting them to the analog inputs, we normally recommend a passive biasing circuit as explained here: use two 1M resistor, as follows:
3.3V
|
Z 1M (or 690k)
Z
|
piezo in ---------- analog in
|
Z 1M
Z
|
GND
This will at least center the signal, so that you will read a symmetric signal (but DC-shifted), and the negative half-wave is more unlikely to clip. Look at the signal, if there is still some clipping (positive or negative), then try adding a resistor in series with the piezo.
Ok I figured it out! The scope helped a lot, thanks! I was using the audio input, and the signal was actually coming in with no distortion. The problem was that the potentiometers I was using to control the volume were noisy, and since they were multiplied together it added a lot of noise to the signal. A 10hz lowpass filter on the potentiometer solved the issue, though I'm not sure why the amount of noise depended on the power input... The only thing that's not quite right is that the gain on the input seems to change strangely, (e.g if I attach the piezo more directly, the volume actually goes down instead of up) even though I've set the gain in the settings, but as long as I don't move it too much I can just set the gain appropriately
if you are using 5V as a voltage reference from the pots, then any noise on that supply rail will be injected straight into your audio signal. We normally use the 3.3V supply rail, as a reference for the potentiometers, as it is sensibly quieter.
Ya I used the 3.3V rail, I think it may have just been too many pots in parallel!
it'd be interesting to look at the 3.3V power supply on the scope when you are powering from 5V/USB vs when you power from lipo: just connect the 3.3V rail straight to the analog input and look at them on the Bela scope.
I've embedded it now so it'll be tough to do, but I'll try that as soon as I can get it back out and report back!
So I finally tested this with a multimeter in series and it seems like it is indeed charging. I read 150mA towards the battery (charging) when the USB is plugged in, and 220mA towards the board when the USB is disconnected. It's crucial to have the 10k resistor in place, or charging won't work.