There are a few ways to do averaging. First, the capacitor can help you if you measure current on the solar cell side, as we discussed. Second, you can put your current sensor through an analog low pass filter which will filter out a good amount of the PWM switching. Third, you can digitally filter or average.
The problem with two values, one for on and one for off, is that you are not accounting for the duty cycle variation. You really want a weighted average with the weights given by D and 1-D. Two values does not do that, but filtering can do the effective averaging and then you only need to sample one value to get the average. There is no one right way to do this, and you will have to figure out a method that meets your criteria and design philosophy.
Some funny things can happen if you are not careful, and I can give one example of an unexpected result that I got once. One time I used digital control with a 100 kHz sample rate, and I used a PWM frequency of 100 kHz. I used external analog filtering on the current sensing, and then sampled the values with an A/D converter. However, since my control rate and my PWM rate were exactly the same and phase locked, the PWM frequency variations in my current readings caused me to always sample at the same point in the AC variation, which resulted in an offset error. The solution was to change my PWM rate to 111,111 Hz which allowed my samples to scan over the entire AC cycle and effectively average out the PMW frequency from the measurement. Many things you did not anticipate will show up when you actually get to building this thing.
The problem with two values, one for on and one for off, is that you are not accounting for the duty cycle variation. You really want a weighted average with the weights given by D and 1-D. Two values does not do that, but filtering can do the effective averaging and then you only need to sample one value to get the average. There is no one right way to do this, and you will have to figure out a method that meets your criteria and design philosophy.
Some funny things can happen if you are not careful, and I can give one example of an unexpected result that I got once. One time I used digital control with a 100 kHz sample rate, and I used a PWM frequency of 100 kHz. I used external analog filtering on the current sensing, and then sampled the values with an A/D converter. However, since my control rate and my PWM rate were exactly the same and phase locked, the PWM frequency variations in my current readings caused me to always sample at the same point in the AC variation, which resulted in an offset error. The solution was to change my PWM rate to 111,111 Hz which allowed my samples to scan over the entire AC cycle and effectively average out the PMW frequency from the measurement. Many things you did not anticipate will show up when you actually get to building this thing.