10 bit analog output

The freq could be as fast as you can bang the bits, essentially the same freq limits as analogWrite() and the PWM. One day I may learn enough to make a library for this. The real speed limitation is the RC filter, which can be anything you want depending on the PWM freq of analogWrite() and if you need to filter for low ripple.

In my application is was necessary to make the output both strong and quiet, but speed was of little concern. So I ended up following it with a very slow RC filter. I cant discuss the application but it involves a voltage more precise than 8 bits "sneaking up" until an event happens, the measurement of interest being the voltage required to trigger the event. If these do not happen within 10% of a supply rail than its a test failure. Omitting the "middle 50%" saved my application one IO pin for each channel, but in general you'd need 2 digital IO pins to augment a PWM to 10 bits.

On start up I write the 0%, 25%, 75% and 100% levels and verify each using analogRead(). Then I bang between 100% and 0% a coupla times and check the step response of my super slow filter. Soon I will also measure a bandgap reference and compensate for Vcc regulation. If all is well I'm ready to test.

The test pops to 75% and pauses for the filter catches up, then it ramps up slowly to 100%. The slew is low so the slow filter does not hurt. It remembers at what level an event triggers on each channel. After 100% it pops to 25%, pauses, then ramps slowly down to 0% to check the lower event thresholds.

Actually after both channels have tripped their events, my application could abandon the remainder of the ramp and drive on, but speed is not important to me.

Perhaps I oughta make a library or funtion that accepts as arguments one PWM pin plus n digital pins, to define an n+8 bit analog out. Then you just write an n=8 bit number. Assuming you put in appropriate resistors and any filtering you might need, your analog appears.