hey Guys I m working on PHOTOVOLTAIC CHARGE CONTROLLER using DsPIC 30F4011..
I have actually completed calcultion simulations and Code testing :
I have written this code on PWM
#include <libpic30.h>
#include <p30f4011.h>
// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, Fcy=30MHz
_FWDT(WDT_OFF); // Watchdog timer off
_FBORPOR(MCLR_DIS); // Disable reset pin
// Function prototypes
void configure_pins();
unsigned int read_analog_channel(int n);
int main()
{
int voltage;
// Set up which pins are which
configure_pins();
while(1)
{
// Analog input 0 controls PWM 1 duty cycle.
voltage = read_analog_channel(0);
PDC1 = (int)((voltage / 1023.0) * 2 * PTPER);
}
return 0;
}
void configure_pins()
{
// Configure RD0 as a digital output
LATD = 0;
TRISD = 0b11111110;
// Configure analog inputs
TRISB = 0x01FF; // Port B all inputs
ADPCFG = 0xFF00; // Lowest 8 PORTB pins are analog inputs
ADCON1 = 0; // Manually clear SAMP to end sampling, start conversion
ADCON2 = 0; // Voltage reference from AVDD and AVSS
ADCON3 = 0x0005; // Manual Sample, ADCS=5 -> Tad = 3*Tcy = 0.1us
ADCON1bits.ADON = 1; // Turn ADC ON
// Configure PWM for free running mode
// PWM period = Tcy * prescale * PTPER = 0.33ns * 64 * 9470 = 20ms
PWMCON1 = 0x00FF; // Enable all PWM pairs in complementary mode
PTCON = 0;
_PTCKPS = 3; // prescale=1:64 (0=1:1, 1=1:4, 2=1:16, 3=1:64)
PTPER = 9470; // 20ms PWM period (15-bit period value)
PDC1 = 0; // 0% duty cycle on channel 1 (max is 65536)
PTMR = 0; // Clear 15-bit PWM timer counter
_PTEN = 1; // Enable PWM time base
}
// This function reads a single sample from the specified
// analog input. It should take less than 2.5us if the chip
// is running at about 30 MIPS.
unsigned int read_analog_channel(int channel)
{
ADCHS = channel; // Select the requested channel
ADCON1bits.SAMP = 1; // start sampling
__delay32(30); // 1us delay @ 30 MIPS
ADCON1bits.SAMP = 0; // start Converting
while (!ADCON1bits.DONE); // Should take 12 * Tad = 1.2us
return ADCBUF0;
}
this code works fine :
Now I working on the control loop:
In voltage-mode control the output voltage increases and decreases as the duty ratio increases and decreases.
The output voltage is sensed and used for feedback. it has two-stage regulation,
it will first hold the voltage to a safe maximum for the battery to
reach full charge. Then it will drop the voltage lower to sustain a "finish" or "trickle" charge.
Has anyone done this or can help me to write the control loop..
it will be a grt help
Thanks !!
I have actually completed calcultion simulations and Code testing :
I have written this code on PWM
#include <libpic30.h>
#include <p30f4011.h>
// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, Fcy=30MHz
_FWDT(WDT_OFF); // Watchdog timer off
_FBORPOR(MCLR_DIS); // Disable reset pin
// Function prototypes
void configure_pins();
unsigned int read_analog_channel(int n);
int main()
{
int voltage;
// Set up which pins are which
configure_pins();
while(1)
{
// Analog input 0 controls PWM 1 duty cycle.
voltage = read_analog_channel(0);
PDC1 = (int)((voltage / 1023.0) * 2 * PTPER);
}
return 0;
}
void configure_pins()
{
// Configure RD0 as a digital output
LATD = 0;
TRISD = 0b11111110;
// Configure analog inputs
TRISB = 0x01FF; // Port B all inputs
ADPCFG = 0xFF00; // Lowest 8 PORTB pins are analog inputs
ADCON1 = 0; // Manually clear SAMP to end sampling, start conversion
ADCON2 = 0; // Voltage reference from AVDD and AVSS
ADCON3 = 0x0005; // Manual Sample, ADCS=5 -> Tad = 3*Tcy = 0.1us
ADCON1bits.ADON = 1; // Turn ADC ON
// Configure PWM for free running mode
// PWM period = Tcy * prescale * PTPER = 0.33ns * 64 * 9470 = 20ms
PWMCON1 = 0x00FF; // Enable all PWM pairs in complementary mode
PTCON = 0;
_PTCKPS = 3; // prescale=1:64 (0=1:1, 1=1:4, 2=1:16, 3=1:64)
PTPER = 9470; // 20ms PWM period (15-bit period value)
PDC1 = 0; // 0% duty cycle on channel 1 (max is 65536)
PTMR = 0; // Clear 15-bit PWM timer counter
_PTEN = 1; // Enable PWM time base
}
// This function reads a single sample from the specified
// analog input. It should take less than 2.5us if the chip
// is running at about 30 MIPS.
unsigned int read_analog_channel(int channel)
{
ADCHS = channel; // Select the requested channel
ADCON1bits.SAMP = 1; // start sampling
__delay32(30); // 1us delay @ 30 MIPS
ADCON1bits.SAMP = 0; // start Converting
while (!ADCON1bits.DONE); // Should take 12 * Tad = 1.2us
return ADCBUF0;
}
this code works fine :
Now I working on the control loop:
In voltage-mode control the output voltage increases and decreases as the duty ratio increases and decreases.
The output voltage is sensed and used for feedback. it has two-stage regulation,
it will first hold the voltage to a safe maximum for the battery to
reach full charge. Then it will drop the voltage lower to sustain a "finish" or "trickle" charge.
Has anyone done this or can help me to write the control loop..
it will be a grt help
Thanks !!