I would primarly expect a software problem. 47 ohm isolation resistor for the output is lower than the suggested datasheet value but not much, instability with capacitive load would be the other explanation.
Anything obviously wrong here?
const unsigned short VREF = 5.00;
unsigned short pwm_duty, pwm2_duty;
int res = 0, res2 = 0;
float R_IN, R_OUT, R2_IN, R2_OUT;
void main() {
ANSELA = 0; // Digital
ANSELB = 0; // Digital
ANSELC = 0; // Digital
ANSELD = 0; // Digital
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISA0_bit = 1; // RA0 pin Input
TRISA1_bit = 1; // RA1 pin Input
TRISA2_bit = 1; // RA2 pin Input
TRISA3_bit = 1; // RA3 pin Input
TRISA4_bit = 0; // RA4 pin OUTPUT
TRISD4_bit = 1; // RC4 pin Input
TRISD5_bit = 1; // RC4 pin Input
TRISD6_bit = 1; // RC6 pin Input
TRISD7_bit = 1; // RC7 pin Input
ANSELE = 0; // Configure RE pins as ANALOGUE
TRISE1_bit = 1; // Configure RE1 pin as Input for Channel 1
TRISE2_bit = 1; // Configure RE2 pin as Input for Channel 2
PORTC = 0; // set PORTC to 0
TRISC = 0; // designate PORTC pins as output
PWM1_Init(10000); // Initialize PWM1
PWM1_Start(); // Start PWM1 on Pin RC2 CH2
PWM2_Init(10000); // Initialize PWM2
PWM2_Start(); // Start PWM2 on Pin RC1 CH1
ADC_Init(); // Initialize ADC
do {
res = ADC_Get_Sample(6); // Get 10-bit results of ADconversion
R_IN = res * VREF/1024.0; // Calculate R1-IN in Volts
res2 = ADC_Get_Sample(7); // Get 10-bit results of ADconversion
R2_IN = res2 * VREF/1024.0; // Calculate 2-IN in Volts
if (RD4_bit &&RD5_bit &&RD6_bit){
R_OUT = R_IN * .82;
R2_OUT = R2_IN * .82;
}
pwm_duty = R_OUT * 51.2; // PWM Duty equals R Out x 51.2
PWM2_Set_Duty(pwm_duty); // Set PWM Duty
pwm2_duty = R2_OUT * 51.2; // PWM2 Duty equals R2 Out x 51.2
PWM1_Set_Duty(pwm2_duty); // Set PWM2 Duty
while(1);
}
Also, by removing channel 2 from the program, or also interestingly by using an external 16MHz crystal instead of the internal 16MHz osc, problem dissappears, any significance I am missing?