MPPT code in picbasic


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2007
    Posts
    27

    Default MPPT code in picbasic

    Hello my friends,
    I have just found a code about MPPT. I couldn't translate in Picbasic. I suppose an error in adjusting pwm duty. If you can translate the code i will be very happy. Thank you for now.
    Best regards.

    #include <16f876.h>
    #DEVICE *=16 ICD=TRUE
    #use Delay(Clock=20000000)
    #use RS232(Baud=9600,Xmit=PIN_C6,Rcv=PIN_C7,brgh1ok)

    float average_ad(byte chan) {

    int i,avg_num = 32;
    float avg = 0, temp_avg = 0;

    set_adc_channel(chan);
    delay_us(100);
    for (i=1; i<=avg_num; ++i) {
    avg += read_adc();
    delay_us(100);
    }
    return(avg/avg_num);
    }

    void pwm1_duty100(long pwm_percent, long pwm_maximum) {

    set_pwm1_duty((pwm_maximum/100)*pwm_percent);
    }

    main()
    {
    CONST float CHARGED = 14.4;
    CONST long NDELTA = -1;
    CONST byte AMP_CHAN = 0, BAMP_CHAN = 3, BVOLT_CHAN = 2, VOLT_CHAN = 1;
    float current, voltage, watts = 0.0, old_watts = 0.0;
    float batamps, batvolts, batwatts;
    float temp_watts, watts100, amp100, volt100;
    long delta = 1, pwm_max, pwm100;
    long boost = 0, boost_counter;
    byte led_count = 0;

    output_low(PIN_C3);
    setup_port_a(ALL_ANALOG);
    setup_adc(adc_clock_div_32);
    setup_timer_2(T2_DIV_BY_1, 49, 1);
    setup_ccp1(CCP_PWM);
    pwm_max = 200;
    pwm100 = 85;
    pwm1_duty100(pwm100, pwm_max);
    output_high(PIN_C3);
    output_high(PIN_C0);
    delay_ms(1000);

    while(TRUE) {
    if (batvolts > CHARGED) {
    delta = NDELTA;
    output_high(PIN_C5);
    }
    else if (old_watts > watts) {
    delta = -delta;
    output_low(PIN_C5);
    }
    old_watts = watts;
    pwm100 += delta;
    if (pwm100 > 100) pwm100 = 100;
    else if (pwm100 < 0) pwm100 = 0;
    pwm1_duty100(pwm100, pwm_max);

    current = average_ad(AMP_CHAN)/40.885;
    voltage = average_ad(VOLT_CHAN)/18.2887;
    batamps = average_ad(BAMP_CHAN)/41.3428;
    batvolts = average_ad(BVOLT_CHAN)/20.4831;

    watts = current * voltage;
    batwatts = batamps * batvolts;

    output_bit(PIN_C0, (++led_count & 0x01));
    delay_ms(500);

    }
    }
    Last edited by showtime; - 29th September 2007 at 21:54.

  2. #2
    Join Date
    Aug 2007
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    Nobody have to help in this point. Also I don't know if it is a problem wishing a code translation. But please help me. I would like just to know if there is an error in this code.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    There's a really few amount of member here who deal with C... hence why there's no real answer to your previous post. There's also few C variant... CCS, Hi-tech, MikroC etc etc etc

    This would help if you tell us what you need to do and if you really understand the MPPT basics...
    Last edited by mister_e; - 1st October 2007 at 21:21.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Aug 2007
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    Of course my target is MPPT project. But I didn't understand anything. I have got some idea about MPPT in theory but not in code level.

Similar Threads

  1. sample code for AT45DB642D in Picbasic Pro
    By itsssyam in forum General
    Replies: 0
    Last Post: - 10th March 2010, 06:01
  2. 16f887 44 pin demo board code problem?
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th December 2008, 14:17
  3. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  4. PicBasic code problems with a 16F84A
    By Lauren Barta in forum mel PIC BASIC
    Replies: 3
    Last Post: - 30th May 2006, 22:50
  5. PicBasic Fundamentals
    By Billyc in forum General
    Replies: 9
    Last Post: - 4th May 2004, 10:04

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts