Hi Mac
Thanks for replying!
I have done some changes according to your suggestion.
I am measuring 4 ADC values (8 samples each) a 16x2 LCD and other interrupts as well.So the loop is bound to be sluggish
I do not expect instantaneous correction in PWM since i am trying to charge a battery and it isn't hazardous.
What i want to achieve is driving a source from a MOSFET to a battery and another load.The other load demands much more current than the battery.
I want to keep the battery charging at 10A and provide the load with whatever current it demands.So i want to keep the dutycycle under check till battery demands 10A current and when load demands more current duty cycle has to be increased
I will write some snippets here...
ADC init
void Init_ADC(void)
{
ADCSC1 = 0x1F; // No ADC channel selected during config
// ADCCFG = 0xF8; // Bus clk, 10-bit, long sampling, clock/2 & low power
ADCCFG = 0x09; // Bus clk, 10-bit, short sampling, clock/2 & high speed
ADCSC2 = 0x00; // S/w trigger, no compare
APCTL1_ADPC7 = 1 ; // Pin I/O disabled for ADP7
APCTL1_ADPC6 = 1 ; // Pin I/O disabled for ADP6
APCTL1_ADPC5 = 1 ; // Pin I/O disabled for ADP5
APCTL1_ADPC4 = 1 ; // Pin I/O disabled for ADP4
}
interrupt 7 void TimerCH1 (void)
{
// Stops Timer1
TPMSC = TIMER_STOP;
ADCSC1_test= ADCSC1; //to unharm other ADC reads which r out of this ISR
ADCSC1 = 0x07 ;
while (!ADCSC1_COCO);
current_adjust=ADCR;
if(current_adjust<=4) current_adjust=4; //min duty
TPMC1V = current_adjust;
ADCSC1= ADCSC1_test ; //to retain other ADC readings
// Restarts Timer1
TPMSC = TIMER_START;
}
void Timer1_init(void)
{
// Timer1 period
TPMMOD = TIMER_OVERFLOW; //200us
//Initial duty cycle
TPMC1V=0;
// Selects PWM Low-true pulses in the Timer1 Channel0 (PTA0/TPM1CH0)
TPMC1SC = 0x024; //flag=0|ch_int_dis=0|MSnBA=10=edge aligned PWM|ELSBA=01=set o/p on compare|00
// Starts Timer1 ELSBA=10=clr o/p on compare
//TPMSC = TIMER_START; //0,TOIE=1,CPWMS=0,CLKSAB=01 PS2-0=011(div/8=1us)
}
Your suggestion to keep TPM enabled does not provide time for other peripherals, so am forced to disable it in ISR.