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.
Hello everybody,
i'm trying to get SFO() function working but without an success. The code is running on C2000 LaunchPad XL with TMS320F28027.
My code is as simple as this:
---
main () {
while (1){
int status, x;
status = SFO_INCOMPLETE;
while (status==SFO_INCOMPLETE) {
status = SFO();
}
if(status!=SFO_ERROR) { // IF SFO() is complete with no errors
EALLOW;
EPwm1Regs.HRMSTEP=MEP_ScaleFactor;
EDIS;
}
}
}
---
The problem is in that SFO() function don't return anything else than 0 and 2 so it can't update HRMSTEPS. I have tried both version of LIB file, standard and "b" version, the same issue. Other header files are included correctly, compilation pass without an problem.
I put some break-points in code and observe all relevant vars from this code. Most of time, looping is done in first "while" statement then exit that loop and skip next "if" branch, because return status was "2".
Also tried similar code in other program, same problem.
What can be an problem here? Maybe some clock configuration (tried 50MHz and 60MHz)?
Thank You in advance.
I have attached an example for SFO() at the 28069 (90MHz).The SFO-function itself will store the new scale factor in register EPWM1.HRMSTEP, no need to do it yourself. I am not sure why your code returns 2 instead of 1. Did you enable the PWM-clocks before you call SFO()?
/* * Lab2_4C.c * * Created on: 03.12.2012 HRPWM * Author: bormann */ #include "F2806x_Device.h" #include "SFO_V6.h" extern void InitSysCtrl(void); Uint16 PWM_Freq = 71; // fPWM = 90MHz/(71+1) = 1.25 MHz Uint16 PWM_Duty = 22; // PWM - duty = 31% active high Uint16 MEP_Steps = 24; // number of MEP steps (150ps) int MEP_ScaleFactor; // Global variable used by the SFO library volatile struct EPWM_REGS *ePWM[PWM_CH] = { &EPwm1Regs, &EPwm1Regs, &EPwm2Regs, &EPwm3Regs, &EPwm4Regs}; void main(void) { Uint16 status; InitSysCtrl(); // 90 MHz 28069 EALLOW; SysCtrlRegs.WDCR = 0x00AF; GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0; // enable pull-up EDIS; do { status = SFO(); // calculate MEP steps and store in HRMSTEP of ePWM1 }while(status == 0); EPwm1Regs.TBCTL.all = 0xC030; /* 1100 0000 0011 0000 * 15-14: 2; FreeRun on Halt * 13 : 0; Phase Direction * 12-10: 0; CLKDIV /1 * 9-7 : 0; HSPCKLDIV /1 * 6 : 0; no SWFRCSYNC * 5-4 : 3; disable SYNCOUT * 3 : 0; use TBPRD shadow * 2 : 0; do not use PHSEN * 1-0 : 0; Count - up mode */ EPwm1Regs.TBPRD = PWM_Freq; /* fpwm = fcpu / (1 * (TBPRD+1) * CLKDIV * HSPCLKDIV) * 1.25 MHz = 90 MHz / (1 * (71+1) * 1 * 1) */ EPwm1Regs.CMPA.half.CMPA = PWM_Duty; // set duty 31% EPwm1Regs.CMPCTL.all = 0; // default mode , shadow enabled EPwm1Regs.AQCTLA.all = 0x0012; // ZRO = 2 ; set on CTR = 0 // CAU = 1 ; clear on CTR = CMPA EPwm1Regs.CMPA.half.CMPAHR = (MEP_Steps << 8); EALLOW; EPwm1Regs.HRCNFG.all = 0x2; // bit 1-0 = 2: falling edge control EDIS; while(1) { EALLOW; SysCtrlRegs.WDKEY = 0x55; // service key #1 SysCtrlRegs.WDKEY = 0xAA; // service key #2 EDIS; } }
I can't find the cause for such behaviors.
In other example/code I have tried, I have proper PWM (HRPWM) initialization code before SFO() call and PWM itself generates correct output signals.
The main problem is in that SFO() function returns "2" which is an error state. In some examples I observed, if that state reach "2", usually program is instructed to STOP processor!?
As I understand the documentation correct, this function need to return something > 2, some "measured" calibration value, but I can't get that.
If someone can post files of some working example for CCS5.x will be great. I can try that code to see does it will work. Maybe I making somewhere other type of misconfiguration which leads to this problem.
I'm "new" to TI MCU platforms, have some experience with other MCUs.
Alex,
when I run my example from my previous post, the "do{...}while(status==0)" is left with status = 1. I never get status = 2. So I guess there is something wrong with your initialization of the PWM. Did you enable the HRPWMENCLK - bit in PCLKCR0? When I intentionally remove this enable instruction from my code (in InitSysCtrl()), I also get status =2.
I got somehow SFO() working from Example_2802xHRPWM_PrdUpDown_SFO_V6.
The similar problem was here:
http://e2e.ti.com/support/microcontrollers/c2000/f/171/p/229662/807606.aspx#807606
I didn't find the exact cause for such behavior, probably somewhere in my project configuration.
Maybe I chose the most complicated module in Piccolo - HRPWM for my first project, but because of that PWM I have choose this MCU ;)
Anyway, I have observed MEP_ScaleFactor and it really change over time, mostly regarding IC temperature, when temperature rise this register have smaller value, not too much, about 2-3-4 steps agains large temperature change (30 ~ 80 ℃).
hello
I'm having the same problem,
Have you solved this problem?
If you have resolved to help me, please
Thank you.