Hi,
Use the ADC to read the voltage, use the CCP module (I'm pretty sure all the models you list have at least one) to create the PWM signal. If you set the ADC resolution to 8 bits it'll match the resolution of the CCP module when using the HPWM command. You can get 10bit resolution from the CCP module but you need to set it up manually - plenty of examples around the forum avaiable.
Basic idea:
Code:
DEFINE ADC_BITS 8
Voltage VAR BYTE
LastReading VAR BYTE
Temp VAR WORD
i VAR BYTE
Main:
' Get a couple of readings and average them to reduce noice.
Voltage = 0
For i = 0 to 15 ' 16 readings
ADCIN 0, Temp
Voltage = Voltage + Temp
Pause 5
Next
Voltage = Voltage >> 4 ' Divide by 16, Voltage now 0 to 255
' Update output only if voltage has changed.
If Voltage <> LastReading THEN
HPWM 1, Voltage, 10000
LastReading = Voltage
ENDIF
Goto Main
/Henrik.
Bookmarks