problems regarding mppt using microprocessors

Discussion in 'The Projects Forum' started by nv.vj1794, Jun 17, 2014.

  1. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Hi,
    I have this project where I'm supposed to build the basic mppt for a solar panel using 8051. I have written the code in C and the hardware part is almost done. However, my code seems to not be working and I cannot pinpoint the problem.
    What I have done is interfaced 8051 with dac0808 and adc0808/0809. I have connected the clock of the adc to an 8051 port. The inputs given via the adc are through channel 1 and 2, voltage and current output from the sensors.
    I have implemented the perturb and observe code with 0 as the initial reference voltage and current. I have to do it with the proper values specified by the PV array but that is for later. Also I have to implement the Incremental Conductance method too, once again later that is.
    The output from the dac is a pwm pulse. This pulse is produced by comparing the changed reference voltage to a triangular wave of 1kHz frequency. The triangular wave is produced inside the microcontroller itself.
    I really am not able to figure out where I'm going wrong.

    Thanks in advance
    Vj
     
  2. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You could try simplifying your code down to the ADC and a LED. Then put a pot on the ADC to adjust the voltage, and set the code to light up the LED when ADC voltage is >X.

    Then you can turn the pot up and down and make sure the ADC is working and is calibrated right, so the LED lights up at the correct voltage.

    Once that is tested and working ok you can put your "perturb and observe code" back in and test that.
     
  3. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Thanks will give it a try.
     
  4. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Well I did give it a try and the thing is this.
    The output is there till it reaches the DAC after that once it passes through the DAC there is no waveform on the oscilloscope. I tried it with LEDs alone and they do glow. But the DAC output is not there.
    Don't know what to do now.
    Someone please help.
     
  5. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Write some simple DAC code to send a number to the DAC and see the result.

    This is a good example of why your code should be in neat separate "modules" that can work independently and be tested independently.

    Too many beginner coders write one long stream of code, then ask "why doesn't it work"?
    :)
     
    djsfantasi likes this.
  6. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Well I did try simulating my codes separately in Proteus but here's the thing. The first time I load a program into Proteus it works the next time I load the same hex file after trying out other hex files the simulator doesn't run the correct file. Do not know why this is happening especially because I know that my code is right as it worked before.
    Been facing this problem with almost all my simulations. It would be really great if someone helped me out with this because at least then I would know if my code is right or wrong.
     
  7. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Well I tried again and now Proteus seems to be working fine.
    Just another doubt. I am trying to create a triangular wave of 1kHz frequency. Some of the codes put up on the internet do not give the right frequency and the code I wrote on my own doesn't either.
    My code is as follows:

    for(a=0;a<0xff;a++)
    { delay();
    DACDATA=a;
    }
    for(a=0xfe;a>0;a--)
    { delay();
    DACDATA=a;
    }

    The delay I gave was FFFE which corresponds to a 2us delay between each value of a and the time period I get is 15ms though. I need 1ms. Can someone please tell me where I am going wrong?
    (I got the delay 2us by dividing 500 by 255 i.e the number of steps.)
     
  8. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    It sounds like the time for the other instructions to execute is being added into each cycle.

    That is the reason to use the internal timer modules, so it will make an accurate frequency and not depend on instruction execution time. :)

    It sounds like you are struggling with this project?
     
  9. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Yup there is no doubt that I am struggling with this project but I want to get it done.
    An I did use TMOD and TCON registers. That's the thing I used them and still I am not getting the correct frequency.
    Also is my logic right in dividing 500 by 255?
    My delay program is this.

    void delay(void)
    {
    TMOD=0x10;
    TL1=0xfe; \\giving the values fffe for a 2us delay
    TH1=0xff;
    TR1=1;
    while(TF1==0);
    TR1=0;
    TF1=0;
    }
     
  10. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Try loading the HI register first, you are loading the LO register first with 0xFE and it might be overflowing before you finish loading HI.

    It also looks to be a poor way to get a 2uS delay. That delay is very short, so it will cause problems with code execution. How many instructions does your micro make during 2uS? :eek:
     
  11. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    It does not seem to matter if I give TH1 first or TL1 first, I get the same result.
    And I checked the sec in Keil and the delay program instead of giving me a delay of 2us it is giving me 18us.
    Is there a minimum time delay that can be generated using 8051 timers because if there is then that's the cause of my problem. I tried searching online for minimum time delay and I did not get any answers.
    Another question: If I want to generate a triangular or sawtooth wave of 1kHz frequency then how do I do it? (Since my current code seems to be giving me the wrong frequency.)
     
  12. RamaD

    Active Member

    Dec 4, 2009
    254
    33
    Remove your delay routine! Your 15ms would reduce, probably not to 1ms.
    Every instruction takes time to execute. Fastest execution time for a 12MHz 8051 for an instruction (assembly) is 1uS. Your delay routine excluding the while, can take more than 10us easily, considering the push/pops on entry/exit, ret, etc., In addition, the program main takes time.

    2uS is too small a time for a 8051. What is your clock frequency?
     
  13. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Yeah I realized that yesterday. The crystal I am using is 24MHz so the only thing I can do at this point is to reduce the frequency of my triangular wave.
    Any other ideas?
     
  14. RamaD

    Active Member

    Dec 4, 2009
    254
    33
    At 24MHz., the fastest executing instruction does it in 0.5uS. A tight hand coded assembly language routine can get you the fastest, and even that is unlikely to reach 1kHz.
    Are you stuck with 8051? Otherwise, there are other 8051 derivatives which execute most of the instructions in a single cycle, offering clock freqs at 25MHz., and above.
     
  15. nv.vj1794

    Thread Starter New Member

    Jun 5, 2014
    14
    0
    Yup I am stuck with 8051.
    So what is the maximum frequency that I can use to generate a triangular wave then?
    In the end all I need is that I get a PWM.
     
  16. RamaD

    Active Member

    Dec 4, 2009
    254
    33
    Initially I thought it was just that you wanted a 1kHz triangular wave. For any reasonable frequency, the 8051 would be tied up fully in generating the triangular wave. There is not much uC time left for anything else.
    The triangular wave, comparator, ... is hardware PWM generators. Change to a uC with a PWM, and write your routines with interrupts. BTW, the uC PWM does not use triangular wave, ... It just allows you to define the width of the pwm, and changing needs to be done by software.
     
Loading...