|
Quote: Under this function, float type WORDS and size are defined . Do you mean "inside' this function? If so, do you know what is inside this function?
Is this a library function for a certain MCU? If so, is there any documentation of this function?
Your initial question is quite unclear, at least to me.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Thank you. Did you see my second reply? I think this information is enough to understand what would be the function. This project is tied on QT5 with STM32 and TI DSP F2806x. widget.h Example File | Qt OpenGL[^]
This project contains IAR,ECILPSE IDE.
A display is added in ST slave, it has APP files. TCP server is involved here. Server is updating the information about DSP register. Its sending modebus Queue initiating this funtion,
Quote: void CModebusTCP::OnReceived(BYTE *pData, int nSize)
Under the function the variables are,
Quote: void MakeGetStatusCMD(void)
{
WORD *pWord;
float *pFloat;
WORD Size;
pWord = (WORD*)Uart1.TxData;
pWord[0] = DSP_CMD_GETTATUS;
pWord[1] = g_AdjustOutput;
pWord[2] = g_RunMode;
pWord[3] = g_Run;
|
|
|
|
|
I am trying to debug a complex firmware CCS V.5 program with compiler V.6.0.2. My control code has access with a PC program. All registers of my application is customized. My goal is to display particular channel voltage, but logically mathematical code should be understand. Here we go
void DispFiltering1(void)
{
float k;
float in_data;
in_data = Register[CH1_VOLTAGE] * 1000 - Vfilt_16;
dVfilt_16 = in_data + (dVfilt_16 * 0.5f);
idvfilt_16 += dVfilt_16;
k = (int)(idvfilt_16 * timeconst_inverse_16);
idvfilt_16 -= k * timeconst_16;
if(k < -slewrate_16) Vfilt_16 -= slewrate_16;
else if(k > slewrate_16) Vfilt_16 += slewrate_16;
else Vfilt_16 += k;
Register[DISP_CH1_VOLTAGE] = Vfilt_16 * 0.001;
in_data = Register[CH1_CURRENT] * 1000 - Vfilt_17;
dVfilt_17= in_data + (dVfilt_17 * 0.5f);
idvfilt_17 += dVfilt_17;
k = (int)(idvfilt_17 * timeconst_inverse_17);
idvfilt_17 -= k * timeconst_17;
if(k < -slewrate_17) Vfilt_17 -= slewrate_17;
else if(k > slewrate_17) Vfilt_17 += slewrate_17;
else Vfilt_17 += k;
Register[DISP_CH1_CURRENT] = Vfilt_17 * 0.001;
}
I will be happy if you can explain why filtering, slewrate and time constant is necessary here? Discuss kindly.
|
|
|
|
|
Your question is about mathematics, the device that you are monitoring, and the data it produces. You should check the documentation that comes with the device.
|
|
|
|
|
This code fragment contains some global variables, we cannot see how they are declared, initialized and probably used somewhere else. We don't see also the constants, maybe there are some comments in their definitions.
Anyway, looks like some (smoothing?) filter.
The best way to understand such code is to add logging with all variables printed, and to understand what happens reading this log. Another way is to make manual calculations with some predefined set of input data, with all code branches applied.
|
|
|
|
|
Quote: This code fragment contains some global variables, we cannot see how they are declared, initialized and probably used somewhere else
Thanks a lot to write here. Yes this code has global variable like Global.c. But this file explains to call internal and external memory and RAM. A summary can find here, DSP Global Variable Specification Syntax[^]
Looking at the first defination,
in_data = Register[CH1_VOLTAGE] * 1000 - Vfilt_16;
Register[CH1_VOLTAGE]=float Register[COUNT_OF_REGISTER];
Vfilt_16 is also a register value.
About k the C2000 digital lib manual says,
Proportional gain is usually applied directly to servo error, however, a feature of this controller is that sensitivity of the proportional path to the reference input can be weighted differently from that of the feedback input. This is achieved through the Kr variable, and provides an additional degree of freedom when tuning the controller. The proportional control law is shown in Equation
v5 (k) = Krr(k) - y(k)
In most situations the weighting gain Kr will be unity.
Its a PID controller equation. Such functions are typically based on integrating the transient error over a fixed time interval.
The DCL.h library header file includes a set of default floating-point values that can be used for
initialization purposes. These configure the proportional path to have unity gain, zero integral gain, output
saturation limits of ±1.
#define PI_DEFAULTS { 1.0f, \
0.0f, \
0.0f, \
1.0f, \
-1.0f, \
1.0f \
}
An example of the C declaration of an initialized PI structure is:
PI pi1 = PI_DEFAULTS;
The formation of the graph can be find here,7.7. Graph Tools — Code Composer Studio 9.3.0 Documentation[^]
|
|
|
|
|
Hello There,
I am a newbie here. I just want to know few things those are really hard to track down. I am trying to debug a existing F/W code mostly written in c or c++. This IDE and compiler is from a particular DSP/MCU company. This code is a complex one and F/W and S/W mixed together. Some codes are not even understandable because I have very limited knowledge in syntax, pointer datatype and flags etc. Manuals and examples can give some ideas.
Now lets talk a specific problem, .c file includes some header dependencies like those are customized, made for particular reason.
#include "DSP28x_Project.h"
#include "Register.h"
#include "CLA.h"
#include "LED.h"
Mentioned register file is customized. I am not going to describe in detail. Before I post a portion of code I should explain a little. In this PI control we are trying to play with register values which may bring the channel voltage that relates with current in terms of different conditional case. Here we go,
Register[CURENT_LIMIT_STATUS] = CURRENT_LIMIT_STATUS_NULL;
if(bSysRun)
{
Voltage_ch1 -= Current_T_ch1 * Register[LINE_DROP_SCALE];
Voltage_ch1 = Voltage_ch1 < 0 ? 0 : Voltage_ch1;
if(Register[USE_LOADSHARE] != 0)
{
Voltage_ch1 -= Register[LOADSHARE_DIFF_CURRENT] * Register[LOAD_SHARE_SCALE_V];
Current_BP -= Register[LOADSHARE_DIFF_CURRENT] * Register[LOAD_SHARE_SCALE_B];
if(Register[RUN_MODE] == MODE_SOLAR)
{
Voltage_ch2 += Register[LOADSHARE_DIFF_CURRENT] * Register[LOAD_SHARE_SCALE_B];
}
}
What I did not understand as follows,
1. Subtract AND assignment operator, what -= means ?
2. what += means ?
3. What does !=0 means in if structure ?
4. What double equals == means ?
|
|
|
|
|
|
|
1. x -= y means subtract y from x and store the result in x.
2. The same for addition.
3. If not equals.
4. if equals.
A single = sign means assign the value on the right to the variable on the left.
|
|
|
|
|
I saw an article about this on the codeproject by
Nish Nishant and it seems pretty simple first let me post his code
BOOL CPreTransTestApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if(m_haccel)
{
if (::TranslateAccelerator(m_pMainWnd->m_hWnd, m_haccel, lpMsg))
return(TRUE);
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
Now let me expain my scenrio I am running a client server TCPI /IP program the server is a z/os mainframe and the client is a MFC C\C++ windows based program which displays data from the mainframe
I can have up to 4 modeless dialog boxes which display data in a rich edit their pointers live are my derived CWinApp
CDBGRApp
I did all the front end work created the accelarator in my resource file had it as selection in my menu "MENUITEM" and put the appropriate message map and message handler in derived CDialog CProgDebug
I then inserted the following code into my derived CWinAppp CDBGRApp
OOL CDBGRApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if (m_haccel)
{
if (debugger[0] == NULL);
else
{
if (debugger[0]->m_hWnd == NULL);
else
{
::TranslateAccelerator(debugger[0]->m_hWnd, m_haccel, lpMsg);
return(TRUE);
}
}
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
debugger[0] is the first of an array defined as
CProgDebug *debugger[4];
After I created the CProgDebug with it rich edit the window didnt seem to take any input mouse or keyboard
Nish in his code didnt specify that after doing TranslateAccelrator and would have to do TranslateMessage and DispatchMessage from the msg structure as I assume that is being taken care of somewhere down the line by the frameWork
|
|
|
|
|
You missed out a test - you should only return TRUE if TranslateAccelerator() succeeds.
By the way, your if(something); else is quite confusing.
|
|
|
|
|
I am changing that so if I get a zero from from
TranslateAccelerator( that means (and can you confirm this) it wasnt one the key strokes I defined right not necessarly an error I would get a zero from TranslateAccelerator maybe thats the problem in my logic
|
|
|
|
|
Here's the Windows docs page: TranslateAcceleratorA function (winuser.h) - Win32 apps | Microsoft Docs[^]
The function returns nonzero when it successfully translates the accelerator, which is when you should not pass the message through to the default handler. Your code is bypassing the default handler entirely when your h_accel and debug variables are set (without checking if the message was a translated keycode).
|
|
|
|
|
thanks if so this code by Nish
BOOL CPreTransTestApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if(m_haccel)
{
if (::TranslateAccelerator(m_pMainWnd->m_hWnd, m_haccel, lpMsg))
return(TRUE);
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
} is incorrect
this code from Microsoft docs is correct
MSG msg;
BOOL bRet;
while ( (bRet = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
}
else
{
if (!TranslateAccelerator(
hwndMain,
haccel,
&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
as it has not TranlateAccelterator wouldnt you agree
|
|
|
|
|
They are both correct.
The first one skips the default handler if the accelerator has been translated.
The second one calls the default handler if the accelerator has not been translated.
|
|
|
|
|
thank you so much for your patience me However the way mine is set is INCORRECT as I dont have an IF testing for the validity of the TranlateAccelarator and that is why my keyboard gets locked becasue I havr return TRUE for all
|
|
|
|
|
|
if (debugger[0] == NULL);
else
{
What is wrong with
if (debugger[0] != NULL)
{
|
|
|
|
|
got a compile error when it I did that but I had semi colon after the open paren so the logic should work regardless I'll work to change it
thanks
|
|
|
|
|
ForNow wrote: I had semi colon after the open paren

|
|
|
|
|
Not to mention the semi-colons on the end of the if line, essentially making it entirely useless.
|
|
|
|
|
Yes, I have never seen that done deliberately before.
|
|
|
|
|
hi
I want to create CtoolBar dynamically, without the resource( RC file) entries.
Load image to Toolbar and set size based on certain condition.
RC file entries makes it predefined.
your help is much appreciated.
|
|
|
|
|