Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
wr2rf-vme
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
wr2rf-vme
Commits
507f927e
Commit
507f927e
authored
Sep 01, 2021
by
Tristan Gingold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libwr2rf: never cross 360 when updating iq dac phase
parent
21c010ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
26 deletions
+10
-26
board.c
software/libwr2rf/board.c
+10
-26
No files found.
software/libwr2rf/board.c
View file @
507f927e
...
...
@@ -223,9 +223,9 @@ int libwr2rf_dac_set_phase_amp(struct libwr2rf_dev *dev, unsigned ch,
float
amplitude
,
float
phase
,
unsigned
verbose
)
{
if
(
!
(
amplitude
>=
0
.
0
&&
amplitude
<=
1
.
0
))
return
-
1
;
if
(
!
(
phase
>=
0
.
0
&&
phase
<=
360
.
0
))
return
-
1
;
return
LIBWR2RF_ERROR_BAD_PARAM
;
if
(
!
(
phase
>=
-
36
0
.
0
&&
phase
<=
360
.
0
))
return
LIBWR2RF_ERROR_BAD_PARAM
;
float
phase_rad
=
phase
*
M_PI
/
180
.
0
;
float
igainf
=
amplitude
*
cosf
(
phase_rad
);
...
...
@@ -235,7 +235,7 @@ int libwr2rf_dac_set_phase_amp(struct libwr2rf_dev *dev, unsigned ch,
int
qgain
=
dac_convert
(
qgainf
);
if
(
!
dac_check_range
(
igain
)
||
!
dac_check_range
(
qgain
))
return
-
1
;
return
LIBWR2RF_ERROR_BAD_PARAM
;
if
(
verbose
)
fprintf
(
stderr
,
...
...
@@ -284,20 +284,13 @@ int libwr2rf_dac_phase_amp_ext(struct libwr2rf_dev *dev, unsigned ch,
float
amplitude
,
float
phase
,
unsigned
verbose
)
{
const
int
phase_step
=
15
;
int
iphase
;
int
iphase
=
(
int
)
phase
;
unsigned
phase_addr
;
int
last_phase
;
int
res
;
/* According to fmod:
the returned value has the same sign as x and a magnitude
less than the magnitude of y. */
phase
=
fmodf
(
phase
,
360
.
0
);
if
(
phase
<
0
.
0
)
phase
+=
360
.
0
;
/* IPHASE is in 0 .. 360. */
iphase
=
(
int
)
phase
;
if
(
!
(
phase
>=
-
360
.
0
&&
phase
<=
360
.
0
))
return
LIBWR2RF_ERROR_BAD_PARAM
;
/* Current phase. */
switch
(
ch
)
{
...
...
@@ -311,29 +304,20 @@ int libwr2rf_dac_phase_amp_ext(struct libwr2rf_dev *dev, unsigned ch,
return
LIBWR2RF_ERROR_BAD_ID
;
}
last_phase
=
libwr2rf_read16
(
dev
,
phase_addr
);
last_phase
=
(
short
)
libwr2rf_read16
(
dev
,
phase_addr
);
while
(
1
)
{
int
dph
=
iphase
-
last_phase
;
if
((
dph
>=
0
&&
dph
<=
phase_step
)
||
(
dph
<
0
&&
dph
>=
-
phase_step
)
||
(
dph
>=
0
&&
dph
>=
360
-
phase_step
)
||
(
dph
<=
0
&&
dph
<=
-
360
+
phase_step
))
{
if
(
dph
>=
-
phase_step
&&
dph
<=
phase_step
)
{
/* Smooth enough, apply directly. */
return
libwr2rf_dac_set_phase_amp
(
dev
,
ch
,
amplitude
,
phase
,
verbose
);
}
if
(
(
dph
>=
0
&&
dph
<=
180
)
||
(
dph
<
0
&&
dph
<
-
180
)
)
if
(
dph
>=
0
)
last_phase
+=
phase_step
;
else
last_phase
-=
phase_step
;
/* Normalize the phase. */
if
(
last_phase
<
0
)
last_phase
+=
360
;
else
if
(
last_phase
>=
360
)
last_phase
-=
360
;
res
=
libwr2rf_dac_set_phase_amp
(
dev
,
ch
,
amplitude
,
last_phase
,
verbose
);
if
(
res
!=
0
)
return
res
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment