PWM on non-PWM digital outputs experiment


#1

Hi,
I need more analogue outputs, and am already using the 10 PWM outputs converted to analogue voltage. So I was thinking of using some of the digital outputs PC0 to PC5 and doing the PWM with the osc/pwm object in the patch, and applying a RC filter on the output to convert to analogue voltage (as I already did on the PWM outputs). I adapted the values resistances to match the 3kHz max rate of the PC0 to PC5 outputs, It works but there are still a lot of artifacts. I suppose it comes from the conversion from output of osc/pwm object (audio signal) to gpio/out/digital object (logic signal).Maybe the logic input of the gpio object can not sample properly the audio output of osc/pwm object.
So my question is: is there a way to toggle properly logic states at 3kHz? or : Is there a way to output digital states at more than 3kHz (for exemple modifying the gpio object as I did on the pwm objects to have a higher pmw rate)?


#2

toggling the digital pin at 3khz does not give you pwm as such. you will have to vary the duty cycle, basically you need much higher then 3khz to get something similar to pwm with a simple toggle. maybe it would be easier to add some sort of external dac that you connect via i2c?


#3

the duty cycle is changed by the pwm object. And yes this is my question: how to make it higher than 3kHz?
Sorry if it was not clear in my first message.


#4

You are trying to do more or less what I'm doing, just I'm using the digital out as a square/pwm audio oscillator.
Check my post (and the reply by Johannes) here:


#5

Not sure why 3khz is not sufficient, an arduino PWM time period cycle is 500hz, is not 3khz more than sufficient to achieve the same and result in a analogue signal post filtering..
Just need an object to control the outputs.,.


#6

In Arduino I normally use a PWM frequency of 31KHz for audio with a cutoff frequency of the filter at 16 KHz, the signal is not very clean, but the carrier is above the hearing limit.
Depending on the type of filtering and how clean you want the signal, 3KHz will be enough or not...
For clean CV signals (pitch CV control) I normally use a PWM frequency 3 or 4 times the cutoff frequency of the filter, and a 4 pole filter... being the cutoff frequency of the filter the higher frequency you will have in the signal.
For pitch CV I want at least 1KHz for the cutoff frequency (less than tha and you hear a lag or portamento all time), so 3KHz is in the limit...


#7

I had a look on the RM0900 manual, but as I expected it's way beyond my programmation skills. Nevertheless I'm going to try to hack a pwm object using the timer 8 (since the other timers are used by the "oficial" pwm outputs) and asigning to the PC0 to PC5 outputs....


#8

Tell me if you get it to work, I'm very intereted in the results...


#9

me too! this is interesting.


#10

Tried to modify the pwm object but without any result, I fear one have to modify the core code. On another side I modified the digital output object to accept signal instead of logic. And it is a lot more stable when using it with the osc/pwm object. however it is not perfect since the max frequency is 3khz so only 1.5khz usable. Maybe @johannes can let us know how to modify digital out object to a higher rate...


#11

The gpio/out/pwm ... objects make use of specific hardware timers, and they're only routable to a limited selection of GPIO's.
Without the use of hardware timers: Axoloti audio object code is scheduled to execute 3000 times per second. Trying to achieve finer-grained control over code execution timing is unlikely to cooperate well with the rest of the firmware.


#12

Thanks, finaly I kept the osc/pwm with digital outputs solution, despite the small instability it is not crucial for the cv it controls.