So I am designing a cheap and simple sound device using the Atmega32U4 uC and stumbled across one problem.
I am using the 10-bit PWM output of the uC to output audio and I want the user to be able to control the output volume using buttons, not a discrete potentiometer. A typical solution would be to just decrease the PWM output duty; but that way I am losing the already low resolution - by decreasing the output volume only by 10dB I already get 60% lower output voltage, and, therefore, I am entering the 8-bit resolution territory already.
That's why I started looking for a cheap hardware volume decreasing solution and I don't want to use a digital potentiometer, since they are relatively pricey. In the end, I came up with the solution shown below; basically, it uses two uC PWM outputs, one to control the volume (VOLPWM) and one to output the audio (OUTPWM); the VOLPWM gets heavily integrated and then the Q1 switches according to the OUTPWM between ground and the VOLPWM output voltage. Notice that the output integration happens after the Q1+R2 pair, pure PWM signal enters the Q1 base.
I've also considered using a push-pull pair instead of Q1+R2, however, I wasn't able to get a decent low level output.
My questions are:
Are there any better solutions to my problem?
Won't the similar value of R2 and R5 be problematic?
What could be the other cons of my solution?