not yet, waiting for you!
For A and B pins you can either use Bela's digital outs via digitalWrite{Once}()
, or use synchronous GPIOs.
For the PWM pin, you have several options:
Hardware pwm
It's unclear to me what the clock/bit depth specs are for this one. I think the bit depth may be 16 bit and the max bit clock is 100MHz, but I am unsure about the details (e.g.: what carrier frequencies are supported ).
something like this works on a BelaMini (this is in bash
)
config-pin P2.03 pwm
PER=4
CHAN=1
DEV=/sys/class/pwm/pwm-$PER:$CHAN
echo $CHAN > /sys/class/pwm/pwmchip$PER/export
echo 1000 > $DEV/period # this is the inverse of the carrier frequency, probably in ns
echo 100 > $DEV/duty_cycle # again, probably ns
echo 1 > $DEV/enable
To do the equivalent from C++, you can use IoUtils::writeTextFile to emulate the echo
.
PRU pwm
(8-bit, fixed 25kHz carrier). See the example Extra/pru-pwm. It can also be modified to increase clock rate and/or bit depth when using fewer than 8 channels
soft PWM
via digitalWriteOnce()
(bit clock is fixed at bck=44100
and bitDepth*carrier = bck
, so for instance 8 bit means a carrier of 44100/8 = 5512Hz). This is done from within the audio thread with something like:
const unsigned int kPwmBits = 8;
const unsigned int kPwmChannel = 0;
float gPwmValue = 0.1; // the higher the value, the more time it spends high. Set this from any thread
bool setup(BelaContext* context, void*)
{
pinMode(context, kPwmChannel, 0, OUTPUT);
return true;
}
void render(BelaContext* context, void*)
{
for(unsigned int n = 0; n < context->digitalFrames; ++n)
{
static int count = 0;
count++;
if(count == kPwmBits)
count = 0;
bool out = gPwmValue > (float(count) / kPwmBits);
digitalWriteOnce(context, n, kPwmChannel, out);
}
}