I'm beginner studying FPGA. I'm confusing a problem.
I have code and the data type I use is fixed-point:
process(clk)
begin
if(clk'EVENT and clk ='1') then
r_amp := to_sfixed (amp,amp'HIGH,amp'LOW);
r_Va := resize (r_amp * to_sfixed(Va,0,-31),r_Va);
r_Vb := resize (r_amp * to_sfixed(Vb,0,-31),r_Vb);
r_Vc := resize (r_amp * to_sfixed(Vc,0,-31),r_Vc);
V_alpha := resize(r_Va/(to_sfixed (2/3,4,-27)*Udc),V_alpha);
V_beta := resize(to_sfixed(0.57735026919,4,-27)*(r_Vb-r_Vc)/(to_sfixed (2/3,4,-27)*Udc),V_beta);
tmp := resize(to_sfixed(0.57735026919,4,-27)*V_beta,tmp);
z1x := resize(V_alpha - tmp,z1x);
z1y := resize(to_sfixed (2,4,-27)*tmp,z1y);
z2x := resize(z1x+z1y,z2x);
z2y := resize(to_sfixed (-1,4,-27)*z1x,z2y);
z3x := resize(z1y,z3x);
z3y := resize(to_sfixed (-1,4,-27),z3y);
end if;
end process;
How to caculate the execution time of all statements in process? if all statements don't finish in 1 clock period, what will happen?
Thank for watching.
You define the clock period in ns and the synt/PR-tools tries to place the logic so this time constraint is fulfilled. If it fails you will get a timing error.
If it is not finished within 1 clk the result is undefined.
Related
I am currently making a little Program in Delphi 10.3 Community Version 26.0.34749.6593. No additional components.
Essentially I draw on TPaintBox which is fitted in a Panel. Everything works fine so far, but when the objects are repainted via "PaintBox1.Repaint" the Objects got the wrong BrushStyle (bsSolid when they should have bsClear e.g.) Of course I tried to pin it down, but I got no luck. But I found out that at the following Point something doesn't work:
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
i: Integer;
fig : ^TFigure;
apen: TPenStyle;
abrush: TBrushStyle;
color1,color2: TColor;
begin
aPen := PaintBox1.Canvas.Pen.Style;
aBrush := bsStyle;
color1 := PaintBox1.Canvas.Brush.Color;
color2 := PaintBox1.Canvas.Pen.Color;
for I:=0 to List.Count-1 do
begin
fig := List.Items[i];
case fig.Typ of
f_Kreis : begin
with Paintbox1.Canvas do
begin
pen.Style := fig.Pen;
Brush.Style := fig.Brush;
pen.Color := fig.PenColor;
brush.Color := fig.BrushColor;
Ellipse(fig.X,fig.Y,fig.X2,fig.Y2);
end;
end;
f_Rechteck : begin
with PaintBox1.Canvas do
begin
Pen.Style := fig.Pen;
Brush.Style := fig.Brush;
Pen.Color := fig.PenColor;
Brush.Color := fig.BrushColor;
Rectangle(fig.X,fig.Y,fig.X2,fig.Y2);
end;
end;
f_Line : begin
with PaintBox1.Canvas do
begin
pen.Style := fig.Pen;
brush.Style := fig.Brush;
pen.Color := fig.PenColor;
brush.Color := fig.BrushColor;
MoveTo(fig.X,Fig.Y);
LineTo(fig.X2,fig.Y2);
end;
end;
end;
end;
PaintBox1.Canvas.Pen.Style := aPen;
bsStyle := aBrush;
PaintBox1.Canvas.Brush.Color := color1;
PaintBox1.Canvas.Pen.Color := color2;
end;
So when the "Brush.Style := fig.Brush;"-Line is called, nothing happens. I went step by step and after these Line "Brush.Style" is still "bsSolid" even when "fig.Brush" is "bsClear"
For explanation: TFigure is my own class. It houses information about a drawing, such as a rectangle. It is the parent class.
Do I miss something. I really am out of Ideas. Can anyone tell me, why nothing happens?
Edit:
For testing I added the lines:
if Brush.Style <> fig.Brush then
ShowMessage('Warnung!');
under
Brush.Style := fig.Brush;
and it actually wont set it on false, though Brush.Style is bsSolid and fig.Brush is bsClear.
You have declared fig : ^TFigure;, but class instances are already references (pointers). Thus you are creating a pointer to reference, and using that pointer as if it were the reference.
Remove the pointer operator and declare
fig: TFigure;
I can't verify whether there are other errors in your code
I am using TChart with a set of TFastLineSeries, created at run time.
Is it possible to use for a half of series the left axis as Y-axis, for another half - the right one, with individual min/max for each axis?
I don't see properties that can assign axes to series or vice versa.
procedure TForm1.FormShow(Sender: TObject);
var
sv: TSoundingVol;
i: Integer;
serT0, serT05, serUllage, serVCG: TChartSeries;
begin
sv := TSoundingVol.Create();
try
Chart1.ClearChart();
Chart1.View3D := False;
Chart1.Legend.CheckBoxes := True;
Chart1.Axes.Bottom.Title.Text := 'Sounding, m';
Chart1.Axes.Left.Title.Text := 'Volume, m³';
serT0 := TFastLineSeries.Create(Chart1);
serT0.Title := 'At Trim 0 m';
serT05 := TFastLineSeries.Create(Chart1);
serT05.Title := 'At Trim +0,5 m (by bow)';
//Following series should use the right axis and own scaling
serUllage := TFastLineSeries.Create(Chart1);
serUllage.Title := 'Ullage (m)';
serVCG := TFastLineSeries.Create(Chart1);
serVCG.Title := 'VCG (Vertical Center of Gravity)';
for i := Low(SB505Data) to High(SB505Data) do begin
sv.Load(SB505Data[i]);
serT0.AddXY(sv.Sounding, sv.AtTrim0);
serT05.AddXY(sv.Sounding, sv.AtTrim0_5);
serUllage.AddXY(sv.Sounding, sv.Ullage);
serVCG.AddXY(sv.Sounding, sv.VCG);
end;
Chart1.AddSeries(serT0);
Chart1.AddSeries(serT05);
Chart1.AddSeries(serUllage);
Chart1.AddSeries(serVCG);
finally
sv.Free();
end;
end;
On a per series basis you can set which Vertical Axis to use.
serUllage.VertAxis := aRightAxis;
serVCG.VertAxis := aRightAxis;
Example of two differently scaled axis used at once.
The individual min/max for each axis is done by:
Chart1.RightAxis.SetMinMax(0, 100);
Chart1.LeftAxis.SetMinMax(10, 8000);
with legend checkboxes you can select each either:
Chart1.Legend.CheckBoxes:= True;
Full example at: http://www.softwareschule.ch/examples/json5.txt
This is my code (don't mind the German variable names):
IF Frage = 1 THEN
BEGIN
Reset(Textdatei);
Writeln;
i := 0;
WHILE NOT EoF(Textdatei) DO
BEGIN
Inc(i);
Readln(Textdatei,Dateiname);
// NUMMER
IF i < 10 THEN
BEGIN
Temp := Copy(Dateiname,2,1); // Speichert position als Str
posTemp := StrToInt(Temp); // position wird als Int gespeichert
pos0 := posTemp;
END;
IF (i < 100) AND (i > 9) THEN
BEGIN
Temp := Copy(Dateiname,2,2);
posTemp := StrToInt(Temp);
pos0 := posTemp;
END;
IF (i >= 100) THEN
BEGIN
Temp := Copy(Dateiname,2,3);
posTemp := StrToInt(Temp);
pos0 := posTemp;
END;
// NAME
posTemp := pos(' ',Dateiname);
posTemp2:= pos('.',Dateiname);
UnknownLength := (posTemp2-1) - posTemp;
Temp := Copy(Dateiname,posTemp+1,UnknownLength);
Name := Temp;
// KG
posTemp := pos('// ',Dateiname);
posTemp2:= pos('kg',Dateiname);
posTemp := posTemp + 2;
UnknownLength := (posTemp2-1) - posTemp;
Temp := Copy(Dateiname,posTemp,UnknownLength);
posTemp := StrToInt(Temp);
KG := posTemp;
//Liste beschreiben
Liste := AddElement(Name, pos0, KG, Liste);
END;
END;
ClrScr;
Writeln('Laden erfolgreich!');
Readkey;
Submenu();
So, this code does not work right, because the txt file that I load contains empty lines. To be more precise: every SECOND line in the txt is empty. That means, that I have to skip every empty line when filling my chained list with the elements from the txt.
How can I tell the compiler to skip every 2 / empty line ?
How can I tell my compiler to only read a certain line ?
If you answer either of my questions I can finally finish my little program.
The inside of my txt looks exactly like this:
#1: Bisasam. // 11 kg
#2: Bisaknosp. // 22 kg
#3: Bisaflor. // 33 kg
So as you can see, every second line is blank and when it tries to load a blank line into my list it crashes.
You can just add an extra Readln to skip the blank line, so your code becomes:
...
WHILE NOT EoF(Textdatei) DO
BEGIN
Inc(i);
// *** read non-empty line containing data ***
Readln(Textdatei,Dateiname);
...
//Liste beschreiben
Liste := AddElement(Name, pos0, KG, Liste);
// *** skip empty line ***
Readln(Textdatei);
END;
...
Note that this assumes that the non-empty lines are the odd lines in the file, i.e. the first line is non-empty, the second line is empty, etc. If it's the other way round then move the Readln(Textdatei); to the start of the WHILE loop instead of the end.
Back on January 7th I updated to the latest version of Indy 10 (I know this is improper etiquette: but how can I tell in the source code the exact version I have?) I recently found a situation where TIDHttp.Free was taking 30 seconds to execute. I traced it to a situation where two TIDHttp objects were instantiated at the same time. It was taking 30 seconds to free one, and then another 30 seconds to free the other. I am pretty certain this was not occurring with the prior version of Indy 10. Once I rewrote my code to free the first object before creating the second, everything worked fine (i.e. no 30 second delay). The code below is a simplified example. Although when I run this there is no delay. Unfortunately I have the IdHttp objects embedded as member of other objects within my framework. And for this reason it has been difficult to simulate using a simple application.
In the code below, my fix was to move the idhttp1.free; call before the TIdHttp.Create for the 2nd instance.
Any ideas? I guess if need be I can try to simplify my implementation.
procedure TForm1.Button1Click(Sender: TObject);
var
idhttp1,idhttp2: TIDHttp;
IdSSLIOHandlerSocket1,IdSSLIOHandlerSocket2: TIdSSLIOHandlerSocketOpenSSL;
begin
idhttp1 := tidhttp.Create(nil);
IdHTTP1.reusesocket := rsTrue;
idhttp1.handleredirects := True;
IdSSLIOHandlerSocket1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdSSLIOHandlerSocket1.reusesocket := rsTrue;
IdHTTP1.IOHandler := IdSSLIOHandlerSocket1;
idhttp1.get('https://www.google.com');
idhttp2 := tidhttp.create(nil);
idhttp2.handleredirects := True;
IdHTTP2.reusesocket := rsTrue;
IdSSLIOHandlerSocket2 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdSSLIOHandlerSocket2.reusesocket := rsTrue;
IdHTTP2.IOHandler := IdSSLIOHandlerSocket2;
idhttp2.get('https://www.google.com');
idhttp1.free;
idhttp2.free;
showmessage('done');
end;
I need to create new windows user as administrator using Delphi
Thanks
you can use the NetUserAdd and NetUserSetGroups functions declarated in the JEDI Headers.
see this simple sample.
program ProjectAddNewUser;
{$APPTYPE CONSOLE}
uses
JclWin32,//Jedi Library
Windows,
SysUtils;
function CreateWinUser(const wServer, wUsername, wPassword, wGroup:WideString): Boolean;
var
Buf : USER_INFO_2;//Buf for the new user info
Err : NET_API_STATUS;
ParmErr : DWORD;
GrpUsrInfo: USER_INFO_0;//Buf for the group
wDummyStr : WideString;
begin
wDummyStr:='';
FillChar (Buf, SizeOf(USER_INFO_2), 0);
with Buf do
begin
usri2_name := PWideChar(wUsername);
usri2_full_name := PWideChar(wUsername);//You can add a more descriptive name here
usri2_password := PWideChar(wPassword);
usri2_comment := PWideChar(wDummyStr);
usri2_priv := USER_PRIV_USER;
usri2_flags := UF_SCRIPT OR UF_DONT_EXPIRE_PASSWD;
usri2_script_path := PWideChar(wDummyStr);
usri2_home_dir := PWideChar(wDummyStr);
usri2_acct_expires:= TIMEQ_FOREVER;
end;
GrpUsrInfo.usri0_name:=PWideChar(wGroup);
Err := NetUserAdd(PWideChar(wServer), 1, #Buf, #ParmErr);
Result := (Err = NERR_SUCCESS);
if Result then //NOw you must set the group for the new user
begin
Err := NetUserSetGroups(PWideChar(wServer),PWideChar(wGroup),0,#GrpUsrInfo,1);
Result := (Err = NERR_SUCCESS);
end;
end;
begin
if CreateWinUser('localhost', 'MyNewUser','ThePassword','MyWindowsGroup') then
Writeln('Ok')
else
Writeln('False');
Readln;
end.
I think the API call you need is NetUserAdd.
First, check if Delphi provides a wrapper for this call. If not, you'll have to write your own. If you don't know how to make Windows API calls from Delphi, you have some more research to do.