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.

With the PWM, can I keep the keep TBPRD loaded and stop TBCTR?

Other Parts Discussed in Thread: TMS570LS1227

I am trying to trigger a PWM from an external clock on a TMS570LS1227. I have the trigger on TZ1 and set up a digital compare event to trigger a sync on the PWM. Works great; it never loses sync. The problem is that the external trigger can stop and start, but the PWM keeps running and the PWM is triggering ADC SOCs. So, I get a bunch of unsynced samples that I perform calculations with. I'm looking for ideas for how can I stop the PWM when I am not receiving an external clock (meaning the clock is a constant low logic). Loading and unloading TBPRD from an interrupt generated by a compare event is a possibility but I'm wondering if there are any better suggestions out there.

  • Hi Sean,

    I have referred your question to our subject matter expert who should get back to you shortly.

    Paul B

  • How many PWM cycles per external sync pulse? What does the externa sync pulse look like? a square wave?

    Sounds to me it is easier to use a NHET pin if you want zero CPU load.

    Regards,

    Haixiao

     

  • Haixiao Weng said:

    How many PWM cycles per external sync pulse? What does the externa sync pulse look like? a square wave?

    Sounds to me it is easier to use a NHET pin if you want zero CPU load.

    Regards,

    Haixiao

     

    16000 cycles per PWM pulse (80Mhz PWM clock, up-down count with TBPRD at 8000). The sync pulse is a square wave. NHET would probably would work; I have to read more on how to use it. Thanks!

  • Is this what you want to do?

    HET0: a 5KHz input sync pulse, but it is not always there.

    HET19: a center aligned (symmetrical) PWM based on this trigger. This signal (either the rising or falling edge can trigger the ADC)

    Here are the HET code: Write to the "UpdCompA" data field to update the PWM duty cycle. The CompB field will be automatically updated once you update the "UpdCompA" data field.

    Pin_ExtTrig .equ 0
    Pin_Dummy .equ 1
    Count_5K .equ 250
    PWM_CompA .equ 150
    PWM_CompB .equ 100
    Pin_PWM .equ 19

    Ext_Trig   BR{ next=CountDown,cond_addr=LoadPRD,pin=Pin_ExtTrig,event=RISE};
    LoadPRD   MOV32 { remote=CountDown,type=IMTOREG&REM,reg=T,data=Count_5K};
    UpdCompA   MOV32 { remote=PWM_SET,type=IMTOREG&REM,reg=T,data=PWM_CompA};
    UpdCompB   SUB { src1=IMM,src2=T,dest=NONE,rdest=REM,remote=PWM_CLR,data=Count_5K,hr_data=0};
    CountDown   DJZ { cond_addr=Ext_Trig,reg=T,data=0};
    Up_OR_Down   MCMP { next=PWM_CLR,cond_addr=PWM_SET,pin=Pin_Dummy,order=REG_GE_DATA,reg=T,data=125};
    PWM_SET   ECMP { next=Ext_Trig,hr_lr=HIGH,en_pin_action=ON,cond_addr=Ext_Trig,pin=Pin_PWM,action=SET,reg=T,data=PWM_CompA,hr_data=0};
    PWM_CLR   ECMP { next=Ext_Trig,hr_lr=HIGH,en_pin_action=ON,cond_addr=Ext_Trig,pin=Pin_PWM,action=CLEAR,reg=T,data=PWM_CompB,hr_data=0};

    Regards,

    Haixiao

  • Thanks Haixiao! This is a great start.

  • Haixiao, I have one more question. I modified your example slightly, since there is no SUB instruction on my processor, and I am unable to see my output. I am using  N2HET1[14] as the trigger input and N2HET1[19] as the output. I can watch the HETADDR register and see that when I enable the trigger, the program will go to addresses 5 and 6. I also see pin 14 toggling in the DIN register, but I never see DOUT change or anything coming out of pin 19. I have set the DIR register to 0x00080000, setting pin 19 as an output. Pins 14 and 19 are not controlled by the pinmux on the the TMS570LS1227, so there's no issue there either. HET clock is at 80MHz, HR is 1 and LR is 8. What do I need to do to see an output on pin 19?

    Pin_ExtTrig .equ 14
    Pin_Dummy .equ 1
    Count_5K .equ 2000
    PWM_CompA .equ 1500
    PWM_CompB .equ 500
    Pin_PWM .equ 19

    Ext_Trig   BR{ next=CountDown,cond_addr=LoadPRD,pin=Pin_ExtTrig,event=RISE};
    LoadPRD   MOV32 { remote=CountDown,type=IMTOREG&REM,reg=T,data=Count_5K};
    CountDown   DJZ { cond_addr=Ext_Trig,reg=T,data=0};
    L0   MCMP { next=L1,cond_addr=PWM_CLR,pin=1,order=REG_GE_DATA,reg=T,data=PWM_CompA};
    L1   MCMP { next=PWM_CLR,cond_addr=PWM_SET,pin=1,order=REG_GE_DATA,reg=T,data=PWM_CompB};
    PWM_SET   ECMP { next=Ext_Trig,hr_lr=HIGH,en_pin_action=ON,cond_addr=Ext_Trig,pin=Pin_PWM,action=SET,reg=T,data=PWM_CompA,hr_data=0};
    PWM_CLR   ECMP { next=Ext_Trig,hr_lr=HIGH,en_pin_action=ON,cond_addr=Ext_Trig,pin=Pin_PWM,action=CLEAR,reg=T,data=PWM_CompB,hr_data=0};

  • I am in vacation today.

    I will get back to your question on Monday.

    If you upload your CCS project, I can take a look.

    Thanks,

    Haixiao

  • Sure, project is attached to this post. Thanks.

    2438.Resolver_NHET.zip

  • Sean,

    I don't want to sidetrack this good discussion - but just noticed you said you don't have the SUB instruction.  If you are using TMS570LS1227 then you have N2HET which does have SUB.  If you are getting errors trying to assemble with SUB the please make sure that you have the correct part set in the HET IDE or that you are running the HET assembler with the -v2 command line option.   If you leave -v2 out, then it thinks you have NHET (instead of N2HET) and NHET does not have SUB...

     

  • Anthony,

    You are correct; I do have a SUB instruction. I was assembling my HET program in HET IDE and bringing the files over to CCS to compile them there. I changed my device configuration to use N2HET in HET IDE and now I see that I have the SUB instruction available. Thanks for pointing that out!

  • Haixiao's code does work, so there is something wrong with mine. I will work on figuring that out.

  • I modified your code slightly to get it working.

    Pin_ExtTrig .equ 14
    Pin_Dummy .equ 1
    Count_5K .equ 2000
    PWM_CompA .equ 1500
    PWM_CompB .equ 500
    Pin_PWM .equ 19

    Ext_Trig   BR{ next=CountDown,cond_addr=LoadPRD,pin=Pin_ExtTrig,event=RISE};
    LoadPRD   MOV32 { remote=CountDown,type=IMTOREG&REM,reg=T,data=Count_5K};
    CountDown   DJZ { cond_addr=Ext_Trig,reg=T,data=0};
    L0   MCMP { next=L1,hr_lr=LOW,en_pin_action=OFF,cond_addr=PWM_SET,pin=1,order=REG_GE_DATA,reg=T,data=PWM_CompA};
    L1   MCMP { next=Ext_Trig,hr_lr=LOW,en_pin_action=OFF,cond_addr=PWM_CLR,pin=1,order=REG_GE_DATA,reg=T,data=PWM_CompB};
    PWM_SET   ECMP { next=Ext_Trig,hr_lr=HIGH,en_pin_action=ON,cond_addr=Ext_Trig,pin=Pin_PWM,action=SET,reg=T,data=PWM_CompA,hr_data=0};
    PWM_CLR   ECMP { next=Ext_Trig,hr_lr=HIGH,en_pin_action=ON,cond_addr=Ext_Trig,pin=Pin_PWM,action=CLEAR,reg=T,data=PWM_CompB,hr_data=0};