I suppose this is a more general question about microcontrollers, but I thought I'd see if anyone here has ideas about it.
I'm looking at ways of scaling the voltage coming out of a pin to interface with analog circuits running at higher voltage, in this case 9v supplies running at virtual GND at 4.5v in some cases I need the PWM to swing from 4.5 to 9v.
one solution I've come up with is to run a voltage divider being 9v -> 100k -> output -> 100k -> PIN. So when the pin is low, the output is 4.5 and goes up from there. Because of potential current draws I'm connecting the output to the non-inverting input of an opamp. I think this should make the current a reasonable amount for the GPIO to handle, at least in output mode (maybe there's a problem when set to input or at boot) and it seems to be working. My question is, is there a better way to do this (interface a microcontroller pin with a circuit at a different ground potential)
one of the advantages of doing it my way as I see is that if I make the voltage divider this way with V+, then I don't have to AC couple the circuit and thus get very stable DC voltages when I run the PWM through a lo-pass etc. Maybe I should just buffer the PWM first, however if I do that then I need to AC couple it so that the LOW state doesn't hit the low rail of the opamp (causing the output to swing up to V+).
Ideas? Possibly a good start to a general discussion about simple ways of dealing with GPIO as control source for low current (i.e. not motor control) situations.