Prince Vegeta
Member level 5
- Joined
- May 29, 2012
- Messages
- 84
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 2,011
Hi
I need to continuously measure feedback voltage from a boost output. I wrote a code but I don't see that it does it correctly...
It should increase/decrease duty cycle in certain circumstances (assumed by me - I am still waiting for someone else to calculate the real ones)...
here's the code:
never mind any undefined variables cuz i defined them (I only pasted this part of code), also some parts here does other things, I only need to check the ADC stuff.
sim in proteus.
thanks
I need to continuously measure feedback voltage from a boost output. I wrote a code but I don't see that it does it correctly...
It should increase/decrease duty cycle in certain circumstances (assumed by me - I am still waiting for someone else to calculate the real ones)...
here's the code:
Code:
void main() {
PORTE = 0;
TRISE = 0;
TRISA = 1;
PORTA = 0;
k_op = 204;
k_min = 179;
k_max = 230;
v_op = 819;
v_min = 717;
v_max = 922;
CCP4CON = 10;
CCPR4H = 0x9C;
CCPR4L = 0x40;
CCP4IE_bit = 1;
CCP4IF_bit = 0;
GIE_bit = 1;
PEIE_bit = 1;
T3CON = 0x41; //Prescaler 1:1, start Timer 1
ADCON1 = 0x0E; // Configure AN0 pins as analog
ADCON0 = 1; // Configure ADC to work with channel 0 (AN0-RA0)
delay_ms(1); // Required for ADC to work properly
ADCON2 = 0x06;
CMCON |= 7; // Disable comparators
GO_bit = 1; // Start convertion
CCP1CON = 0x0C; // CCP1 configured as PWM (RC2 pin)
k = 127;
PWM1_init (1000);
PWM1_set_duty (k); // initialize PWM with 80% duty cycle
PWM1_start();
while(1){
//Do whatever else is required
v = ADC_Read (0); // read boost's output voltage
/////* duty cycle control */////
if ( v >= 819 ) { // if output voltage >= reference value:
if ( v >= 922 ) { // if output voltage exceeds max voltge, then:
k = k_max; // output max duty cycle then,
k--; // decrease duty cycle
}
}
if ( v <= 819 ) { // if output voltage <= reference value:
if ( v <= 717 ) { // if output voltage is below min voltage, then:
k = k_min; // output min duty cycle then,
k++; // increase duty cycle
}
}
} // end while loop
} // end main loop
never mind any undefined variables cuz i defined them (I only pasted this part of code), also some parts here does other things, I only need to check the ADC stuff.
sim in proteus.
thanks