newaetech / chipshouter-picoemp

Why not run micropython on your EMFI tool?
405 stars 52 forks source link

Request HVPWM explanation #30

Open gmgunderground opened 1 month ago

gmgunderground commented 1 month ago

I'm looking inside the C source code, can someone explane the following function? Especially the used values.

void picoemp_enable_pwm(float duty_frac) {
    if(pwm_enabled) {
        return;
    }

    // Get PWM slice
    uint32_t slice = pwm_gpio_to_slice_num(PIN_OUT_HVPWM);
    gpio_set_function(PIN_OUT_HVPWM, GPIO_FUNC_PWM);

    // Set up clock divider
    float target_frequency = 25;
    float divider = clock_get_hz(clk_sys) / target_frequency;
    pwm_config config = pwm_get_default_config();
    pwm_config_set_clkdiv(&config, divider);
    pwm_config_set_wrap(&config, UINT16_MAX);

    // Init PWM, but don't start it yet
    pwm_init(slice, &config, false);
    // pwm_set_chan_level(slice, PWM_CHAN_A, 800); // pretty sure this line is pointless
    pwm_set_freq_duty(slice, PWM_CHAN_A, 2500, duty_frac);
    pwm_set_enabled(slice, true);
    pwm_enabled = true;
}

what the The duty_frac is used for? How is correlated to the power? What are the bahavior of the following parameters? pulse_time=5, pulse_power=0.012200 Are parameters that it's worth a change? All are changable parameters from serial interface, bat is not explaned haw they can be used and wht they produce on charge of HV.

colinoflynn commented 1 month ago

It might make more sense looking at the micropython source: https://github.com/newaetech/chipshouter-picoemp/blob/main/firmware/micropython/cspico_simple.py#L16

That has the short note that things were basically just empirically tuned! So there's no real magic... you could play around with things and see what happens to the charge voltage and/or recovery time?