Hi,
I'm trying to had some additional analogue outputs through PWM output using LP filter. Anybody can tell me where is specified the frequency of PWM pins?
Thanks
PWM output pin frequency
On this post https://sebiik.github.io/community.axoloti.com.backup/t/questions-about-pwm-output-and-a-d-input-12-bit/746/3
@johannes says it's possible to change pwm freq, hacking the axoloti_board.c file. I opened it but did'nt find anything that look like PMW freq setting. Where can I change it? and what would be maximum frequency?
The PWM initialization has moved to the gpio/out/pwm ...
objects.
In the Init Code of, say, gpio/out/pwm t3
you find static const PWMConfig pwmcfg = {400000, /* 400kHz PWM clock frequency. */
...
4096, /* PWM period is 4096 cycles. */
NULL,
400000 is the timer clock in Hz.
4096 is PWM period in ticks.
Divide these and you get the 97.65Hz cycle frequency.
Essentially the timer clock comes from an 84MHz clock divided by any factor between 1 and 65536.
So the maximum cycle frequency at 4096 steps should be 20.5kHz.
Fantastic! So I guess I can change the number of steps to let's say 255, for 8 bit resolution and high frequency. Does it make axoloti unstable or change some time related functions like it does on arduino?
On the init code of T3 I find this:
palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATE(2));
on the XML code I don't find the bit of code you told neither...
If you're using software version 1.0.11, please do a "sync libraries" (File menu). Or maybe upgrade to the fresh 1.0.12 release.
has anyone implemented this?
Ive considering doing this, using a opamp as described here
4096 steps, at 20khz is more than enough, as I'm just planning on using it as control voltage.
in the circuit above, its using the opamp as a filter (i think?!) , can i also configure it at the same time as a non-inverting amp, so that i can get to 0..5v. I assume I can , no?
(btw: are the analog outs suitable for audio or are there likely to be aliasing issues?)
Yes I did it, it works perfectly, Analogue outputs 0-10V, I have less steps to have a higher frequency PWM, since I'm using it has a midi-Cv converter no need to have more than 127 steps. Never tried for audio but should be a 7 bit audio output...
Hi johannes:
I modified the PWM frequency succesfully, but can you clarify a bit about what those numbers mean?, so I can decide wich is the best choice.
I see everobody is assuming that PWM period in ticks (4096 in the default configuration) is the resolution, so 4096 is 12bits, 256 is 8 bits, and so on. Can you confirm that?
Also, if I choose to divide 84MHz by a small number (2 or maybe 4 is what I have in mind), will that affect performance or have any side effect?.
Basically I want a CV output of 12 bits at a maximum frequency of 1KHz, so I want a PWM frequency a lot higher than that, to let the output filter clean the CV signal as much as it can. (I will use a 4 pole filter with a corner frequency of 1KHz).
Thank you.