This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UCD3138的PSFB程序中的main.c主函数文件中未调用相关函数定义文件也能烧写程序并运行

Other Parts Discussed in Thread: UCD3138, UCD3138HSFBEVM-029, UCD3138PSFBEVM-027

如题,用的是PMBUS烧写程序,JTAG和SCI口未使用

  • 你好,不能明白你的问题是什么?

    可否将问题讲的具体一些

  • 主函数main.c文件中是这样的

        init_gpio();

        init_pmbus();

        init_dpwm();

        init_adc12();
        
        init_protection();

        init_voltage_loop();

        init_current_loop();

        init_light_load_configuration();

        init_miscellaneous();

        init_timer_interrupt();没有这一类的函数调用文件,我想知道程序运行时芯片是怎么工作的?毕竟是从主函数开始运行,如果没有调用函数,程序是怎么执行的?

  • UCD3138的程序分成如下几大部分:

    1. 背景环,即for循环(死循环),初始化完成后,程序一直在其中运行;

    2. 标准中断,每100us或200us产生一次标准中断(时钟中断),用以运行状态;

    3 快中断,有异常故障等场景时,触发快中断。

    因此,程序的执行是这样的:程序一直运行在背景环,等待标准中断或快中断的触发。

  • 我的情况是:在for循环之前没有任何的中断初始化和使能,for循环内也没有,可能是我没有理解内部程序,能否帮我指出中断初始化和使能的具体代码。详情可以查看附件

  • 时钟中断是这个函数:init_timer_interrupt();

    通过这两个语句知,函数还使用了DPWM2周期中断和模拟比较器中断

    write_firqpr (0x0A000000); //make them all irqs except FAULT_INT, DPWM2
    write_reqmask(0x0A020000); //enable FAULT_INT and PWM0_INT, DPWM2

    而DPWM2周期中断和模拟比较器中断的初始化是通过下语句完成的:

    FaultMuxRegs.ACOMPCTRL0.bit.ACOMP_B_INT_EN = 1; //enable ACOMP-B interrupt
    FaultMuxRegs.ACOMPCTRL2.bit.ACOMP_E_INT_EN = 1; //enable ACOMP-E interrupt
    Dpwm2Regs.DPWMINT.bit.PRD_INT_EN =1;

  • main主函数里面没有引用时钟中断:init_timer_interrupt(); ,你看到的时钟中断是被 /*            */ 屏蔽掉的,这回把附件  /*     */  中的程序去掉了,可以查看上面提到的某些中断并未引用。

  • 明白了,这个程序应该是在调试时使用的,屏蔽了各个中断。

    现在只是配置DPWM2 和 DPWM3发固定占空比的脉冲出来。因为调用了pmbus_handler();  是可以下载和通信的。

    正常的程序是不能这样设计的。

  • 这个程序就是TI工程师给的,如果只是调试程序,那我想知道哪里可以得到正常的标准程序?  还是说将这个程序手动去改一些部分。

  • 可以请那位TI工程师确认下,这个程序应该只是开环调试使用的,不是最终版本的。

    我手上有这份程序(不一定是最新的),其中main.c的内容如下,请参考:

    #define MAIN 1

    #include "system_defines.h"
    #include "Cyclone_Device.h"
    #include "pmbus_commands.h"
    #include "pmbus.h"
    #include "variables.h"
    #include "function_definitions.h"
    #include "software_interrupts.h"
    #include "cyclone_defines.h"

    void init_interrupts(void)
    {
    TimerRegs.T16PWM2CMP0DAT.all = 1587; //Threshold to send the pwm low. Approx 10KHz. by spec.64ns clock period
    TimerRegs.T16PWM2CMP1DAT.all = 0xffff; //Threshold to send the pwm high
    TimerRegs.T16PWM2CMPCTRL.all = 2; //Enables compare 0 (reset) interrupt
    TimerRegs.T16PWM2CNTCTRL.all = 0x00c; //PWM counter is running & enables PWM counter reset by compare action on compare 0

    // FaultMuxRegs.EXTFAULTCTRL.bit.FAULT1_POL = 1; //rising edge
    // FaultMuxRegs.EXTFAULTCTRL.bit.FAULT1_INT_EN = 1; //enable fault detection pin interrupt
    // FaultMuxRegs.EXTFAULTCTRL.bit.FAULT1_DET_EN = 1; //enable fault detection
    // MiscAnalogRegs.IOMUX.bit.JTAG_DATA_MUX_SEL = 3; //TDO/TDI Pin Mux Select as: Fault0 & Fault1

    disable_interrupt();
    disable_fast_interrupt(); //make sure fast interrupt is disabled
    write_reqmask(CIMINT_ALL_PWM2_COMP | CIMINT_ALL_FAULT_MUX);//CIMINT_ALL_DIGI_COMP);
    write_firqpr (CIMINT_ALL_FAULT_MUX);
    enable_fast_interrupt();
    enable_interrupt();
    }


    /*
    Dpwm0Regs.DPWMINT.bit.PRD_INT_SCALE = 1; // generate an interrupt on each 16 switching cycles(used to reset the integrator)
    Dpwm0Regs.DPWMINT.bit.PRD_INT_EN = 0;

    disable_interrupt();
    disable_fast_interrupt(); //make sure fast interrupt is disabled
    write_reqmask(CIMINT_ALL_DPWM0 | CIMINT_ALL_PWM2_COMP ); //enable pwm2cmp and DPWM0 interrupt(End of 16th period)(int-priority29)
    write_firqpr (CIMINT_ALL_DPWM0); // DPWM0 interrupt(End of 16th period) is mapped to FIQ
    enable_fast_interrupt();
    enable_interrupt();
    */

    void init_variables(void)
    {
    supply_state = STATE_IDLE;
    //supply_state = 12;
    current_share_kp = 1000;
    current_share_ki = 10;
    fault_status = 0;
    debug_buffer[0]=1;
    debug_buffer[1]=2;
    debug_buffer[2]=3;
    debug_buffer[3]=4;
    debug_buffer[4]=5;
    debug_buffer[5]=6;
    debug_buffer[6]=7;
    debug_buffer[7]=8;
    }

    void main()
    {
    volatile unsigned int dummy;
    if(GioRegs.FAULTIN.bit.FLT3_IN == 0)// Re-Check pin assignment (ADC_EXT/SYNC may be?)
    {
    //clear_integrity_word();
    }

    init_gpio();
    restore_default_all();
    init_variables();
    configure_vin_on_off_thresholds();
    configure_vout_cmd();
    configure_ton_rise();
    init_vout_fault(); // Analog comparator B
    init_uart0();
    init_pmbus();
    init_front_end0();
    init_front_end1();
    init_front_end2(); //
    init_filter0();
    init_filter1();
    init_filter2();
    look_for_interrupted_dflash_erase();
    init_ipri_cycle_by_cycle();
    // init_cpcc();
    current_share_int_state = (EADC_DAC_TARGET << CS_INT_EXP);

    #ifdef SINGLE_FRAME_ENABLE
    init_dpwms_for_single_frame();
    #else
    init_dpwms();
    #endif

    init_loop_mux();
    handle_light_load_mode_configuration();
    // init_current_sensing_hardware();
    init_ADC_polled();
    init_faults();
    #ifdef IDE_ENABLE
    init_ide();
    #endif
    init_prebias();
    init_interrupts();
    dummy = FaultMuxRegs.FAULTMUXINTSTAT.all;


    Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_EN = 1;
    Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_VAL= 1;

    FaultMuxRegs.DCOMPCTRL0.bit.CNT_THRESH = 1;
    FaultMuxRegs.DCOMPCTRL0.bit.FE_SEL = 0;
    FaultMuxRegs.DCOMPCTRL0.bit.COMP_POL = 1;
    FaultMuxRegs.DCOMPCTRL0.bit.THRESH = 850;

    FaultMuxRegs.DPWM0FLTABDET.bit.DCOMP0_EN=1;
    FaultMuxRegs.DCOMPCTRL0.bit.INT_EN=1;

    //FaultMuxRegs.DCOMPCTRL0.bit.CNT_CLR = 1; //clear DCOMP reading
    //FaultMuxRegs.DCOMPCTRL0.bit.CNT_CLR = 0;

    FaultMuxRegs.DCOMPCTRL0.bit.COMP_EN=1;


    for(;;)
    {
    if (erase_segment_counter > 0)
    {
    erase_task();
    }
    pmbus_handler();


    // FeCtrl0Regs.EADCDAC.bit.DAC_VALUE=800;


    /*
    if (Interrupt_Flag==3)
    {
    //Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_VAL=1;
    //disable_fast_interrupt();
    //write_firqpr (0x00000000);
    CimRegs.FIRQPR.all = (0x00000000);
    } */
    }
    }


    /*
    if (Interrupt_Flag==3)
    {
    Dpwm3Regs.DPWMCTRL1.bit.GPIO_A_VAL=1;
    disable_fast_interrupt();
    }
    */


    //Dpwm0Regs.DPWMINT.bit.PRD_INT_EN = 0;
    //
    // CimRegs.FIRQPR.all = (0x00000000);
    #pragma INTERRUPT(c_int00,RESET)

    void c_int00(void)
    {
    main();
    }

  • 这个是PSFB的主函数吗? 还有除了主函数文件,其他文件应该也有不同,能不能麻烦通过附件把整个程序给我,压缩成rar后应该可以发过来的,闭环的PSFB程序

  • 看了这个例子真是受益匪浅,请问可以共享一下PFC的例程吗?

  • 可以点击下确认答案。我找下PFC的

  • 能把UCD3138HSFBEVM-029的参考代码发给我吗?我邮箱是377517827@qq.com,谢谢!

  • Neil Li 

           你好!

        能否把UCD3138的例程序发给我,最好简单的(开环)和闭环的都有,我从额store.ti.com买的 UCD3138PSFBEVM-027,都现在都没要到源代码!

  • TimerRegs.T16PWM2CMP0DAT.all = 1587; //Threshold to send the pwm low. Approx 10KHz. by spec.64ns clock period
    TimerRegs.T16PWM2CMP1DAT.all = 0xffff; //Threshold to send the pwm high
    TimerRegs.T16PWM2CMPCTRL.all = 2; //Enables compare 0 (reset) interrupt
    TimerRegs.T16PWM2CNTCTRL.all = 0x00c; //PWM counter is running & enables PWM counter reset by compare action on compare 0
    Dpwm2Regs.DPWMINT.bit.PRD_INT_SCALE = 2; // generate an interrupt on each 16 switching cycles(used to reset the integrator)
    Dpwm2Regs.DPWMINT.bit.PRD_INT_EN = 1;

    您好,请问您黄色的那句话表示的意思是什么?我参考了技术文档,但是没有太理解他的意思

    This value scales the period interrupt signal from an interrupt every switching cycle to 16 switching cycles,是说将上面PWM2的compare中断变成每16个周期触发一次吗?也就是每过16次compare 匹配进一次中断吗?然后给它赋值为2又是什么意思呢?

  • 意思就是调整中断时间为每个周期进一次中断,或者N个周期进一次中断的意思啊。

    Bits 3-0: PRD_INT_SCALE – This value scales the period interrupt signal from an
    interrupt every switching cycle to 16 switching cycles
    0000 = Period Interrupt generated every switching cycle (Default)
    0001 = Period Interrupt generated once every 2 switching cycles
    0010 = Period Interrupt generated once every 4 switching cycles
    0011 = Period Interrupt generated once every 6 switching cycles
    0100 = Period Interrupt generated once every 8 switching cycles
    0101 = Period Interrupt generated once every 16 switching cycles
    0110 = Period Interrupt generated once every 32 switching cycles
    0111 = Period Interrupt generated once every 48 switching cycles
    1000 = Period Interrupt generated once every 64 switching cycles
    1001 = Period Interrupt generated once every 80 switching cycles
    1010 = Period Interrupt generated once every 96 switching cycles
    1011 = Period Interrupt generated once every 128 switching cycles
    1100 = Period Interrupt generated once every 160 switching cycles
    1101 = Period Interrupt generated once every 192 switching cycles
    1110 = Period Interrupt generated once every 224 switching cycles
    1111 = Period Interrupt generated once every 256 switching cycles

  • Jason 你好。感谢你的回答。还有一个问题想请教你,我在029EVM的configuration_function.c里面看到了一段代码:

    void configure_vout_cmd(void)
    {
    struct qnote constant_DAC_VALUE_SCALER = {DAC_VALUE_SCALER, 0};
    pmbus_dcdc_config_translated[0].vout_cmd = qnote_linear16_multiply_fit14(constant_DAC_VALUE_SCALER, pmbus_dcdc_config[0].vout_cmd, -VOUT_MODE_EXP);
    FeCtrl0Regs.RAMPDACEND.all = pmbus_dcdc_config_translated[0].vout_cmd;
    }

    其中,DAC_VALUE_SCALER=996,是宏定义的,请问这个乘法函数表示什么意思呢?为什么是设置为996? pmbus_dcdc_config[0].vout_cmd=6144,VOUT_MODE_EXP=9,这样算下来刚好是11952,赋值给DCA作为电压环的12V。 我不明白的是996的来历,以及VOUT_MODE_EXP=9的含义,希望您能给我解答一下,不甚感激!

    而且{DAC_VALUE_SCALER的说明是:DAC_VALUE_SCALER is included to convert the voltage to DAC LSBs. 但是根据TI的相关资料显示,DAC单位是1.5625mv/bit. 

  • 请问UCD3138的CPCC功能是怎样实现的?

  • 您好,我将此程序编译成功,下载到40引脚的ucd3138中,pmbus通信不上,是什么原因呢?

  • 能把你的UCD3138HSFBEVM-029的原代码发我一份吗,我买了这款DEMO板,至今没有申请到程序,zszwnm@126.com  或者加我QQ348440333.我们聊聊一些合作的事情

  • 请问下,这个程序是开环的吗?

  • PWR027_PSFB_play_vin  此例程是开环的吗? 有闭环的程序吗?