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.

TMS320F28022: Transmit only for use with C2000/AFE031 App Note, replaces TMS320F28379

Part Number: TMS320F28022

Hello,

We are porting the transmit-only software example for this app note (http://www.ti.com/lit/an/sprac94b/sprac94b.pdf

This uses 2 HRPWM outputs on GPIO0 and GPIO2.

We've gotten pretty close but the HRPWM output is still a little off from the desired frequency.

  • The output on GPIO0 needs to be 131.25kHz but the closest we have gotten is 131.205kHz. This a 2.6ns variation or about 14.5 HRPWM cycles.
  • We changed the EPwm1Regs.TBPRD register to 1 + (CLK_FREQ / SPACE_FREQ) which got us from 17ns off to 2.6ns off.

What register we can use now to fine tune this last 2.6ns variation? We are thinking there might be a HRPWM register we can alter.

Thanks!

  • Nicholas,

    1. Are you running the SFO? If so, how frequently? This should remove some small drifts in frequency due to a variety of causes.
    2. How accurate is your SYSCLK input? Are you using a XTAL or the internal oscillator? 

    Is the output always off by exactly 45Hz, or does that drift  to say 50Hz or 40Hz sometimes?

    Regards,
    Cody 

  • Hi Cody,

    I'm running the SFO like this, with the #ifdef being on or off:

        for(;;) {
    
    #if 1
    		status = SFO_INCOMPLETE;
    		while  (status== SFO_INCOMPLETE) { // This should automatically set HRMSTEP, do this after HRPWM_Config()
    		
    			status = SFO();
    			if (status == SFO_ERROR) {
    
    				error();  // SFO function returns 2 if an error occurs & # of MEPsteps/coarse step exceeds maximum of 255. 
    			}
    		}
    		
    		status = SFO_INCOMPLETE;	// Do it again...
    
    		nCompareFineMarkPeriod		= (int)(MARK_FRACTION  * (float)MEP_SCALE_FACTOR) << 8;
    		nCompareFineSpacePeriod		= (int)(SPACE_FRACTION * (float)MEP_SCALE_FACTOR) << 8;
    		
    		nCompareFineMarkDutyPeriod	= (int)(MARK_DUTY_FRACTION  * (float)MEP_SCALE_FACTOR) << 8;
    		nCompareFineSpaceDutyPeriod	= (int)(SPACE_DUTY_FRACTION * (float)MEP_SCALE_FACTOR) << 8;
    
    #endif
        }
    

    The 2802x appears to default to the external crystal, I've tried it with and without this code to switch to the internal oscillator:

    	CLK_Handle myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
    	CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
    

    I really appreciate any insights you might have.

  • The output will drift between 131.15kHz and 131.3kHz on the F2802x, and it can take half an hour to drift that much.

    The F2802x has about 100 times more jitter than the F28379D does.

    The amount of jitter I'm seeing might suggest the issue might be with the hrpwm??

    The  S-FSK example code for the F28379D had hard coded numbers for CMPA, CMPB, TBPRD, and TBPRDHR.  As it turns out, the values don't multiply the frequency divisor fraction by the MEP_scale_factor, but they are simply multiplying the frequency divisor fraction * 256 to get the hrpwm period value.  In that same example code, the EPwm1Regs.HRMSTEP.bit.HRMSTEP is hard coded to 55 and it doesn't appear to call SFO after initialization.  Yet that works perfectly.

    I've tried multiplying the frequency divisor fraction by 256, and  I've also tried this after calling SFO:

    nCompareFineMarkPeriod = (int)(MARK_FRACTION  * (float)MEP_SCALE_FACTOR) << 8;

    Which is the correct way?  Why does the F28379D multiply by 256 and set the hrmstep to 55?

    I've tried setting the counter mode to TB_COUNT_UPDOWN, if I do that, my pwm period is defined as:

    #define MARK_PERIOD (((float)CLK_FREQ / (float)MARK_FREQ ) / 2) 

    If I set it to TB_COUNT_UP, TBPRD is defined as

    #define MARK_PERIOD (1 + ((float)CLK_FREQ / (float)MARK_FREQ ) ) 

    No idea why I'm seeing 100 times more jitter on the F2802x.

    Thanks!

  • The MEP_ScaleFactor appears to dither between 117 and 118 after going through the SFO() loop.  It seems like the right thing to do, provided that it dithers with the right frequency...

  • Hi Jeff,

    I wouldn't recommend running the SFO continuously. It really only needs to be run at initialization or when conditions change in your system (temperature or supply voltage). If you don't have ways of telling when your system conditions change then you can set it up to run periodically based on how quickly you expect conditions may possibly change in your system. For this debug, let's just set it to run once at initialization and we can work on that periodic integration once we get everything else working.

    Can you post the code you are using? We have bits and pieces from your posts, but I think it would help to be able to see the big picture. Specifically, the initialization routines and any control loops which modify compare or period values.

    To answer a few of your questions:

    - The MEP scale factor is multiplied by 256 because the value is stored in the upper 8 bits of the register. This is just shifting it into place before writing it to the register.
    - Don't hard code the HRMSTEP value. Use the SFO. I'll work on getting that updated.

    More questions for you:
    - What is your SYSCLK frequency?
    - Does the frequency of TBCLK = SYSCLK?

    Regards,
    Kris
  • Hi Kris,

    I really appreciate the help.

    As far as the SFO() goes, I get the same result if I run it continuously or just once at initialization.

    I need to further clarify the  S-FSK example code for the F28379D, it wasn't multiply 256 to shift to the left by 8.

    It's doing this: 

    EPwm1Regs.TBPRDHR = (243U << 8);

    In this case, the 243 is given by: (200Mhz / 131.25kHz / 4 (prescaler)) * 256.   (I would expect it to be multiplied by MEP_ScaleFactor)

    This 243 is then shifted to the left by 8 to be in the upper byte.

  • Hi Jeff,

    Thanks for the additional information. I would like to get my hands on your project so that I can run it locally and get you back on track as soon as possible. Could you zip up your CCS project (make sure all the referenced source code gets included) and upload it here?

    Regards,
    Kris
  • Hi kris,

    I'm trying to sanitize my code.  Is it possible to email you a copy of it?

  • Sure, I just sent you an email on the email address associated with your myTI account.

    Regards,
    Kris
  • Jeff,

    Is the issue resolved? If so, pls close this post.