Mercurial > hg > fxanalyse
comparison ad9912.c @ 259:6c748ed6a7c5
Stricter error checks ad9912 ramp frequency function
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 16 Jun 2015 14:33:36 +0200 |
parents | 5296f3bcd160 |
children | ebbe0f198322 |
comparison
equal
deleted
inserted
replaced
258:5296f3bcd160 | 259:6c748ed6a7c5 |
---|---|
90 * Ramp DDS frequency from @f1 to @f2 in steps @fstep with 0.01 | 90 * Ramp DDS frequency from @f1 to @f2 in steps @fstep with 0.01 |
91 * seconds delay after each step. | 91 * seconds delay after each step. |
92 */ | 92 */ |
93 int ad9912_ramp_frequency2(struct ad9912 *d, unsigned channel, double f1, double f2, double fstep) | 93 int ad9912_ramp_frequency2(struct ad9912 *d, unsigned channel, double f1, double f2, double fstep) |
94 { | 94 { |
95 int r = 0; | |
95 const int delay = 10000; | 96 const int delay = 10000; |
96 | 97 |
97 /* f2 > f1 */ | 98 /* f2 > f1 */ |
98 while ((f2 - f1) > fstep) { | 99 while ((f2 - f1) > fstep) { |
99 f1 += fstep; | 100 f1 += fstep; |
100 ad9912_set_frequency(d, channel, f1); | 101 r = ad9912_set_frequency(d, channel, f1); |
102 if (r < 0) | |
103 return r; | |
101 usleep(delay); | 104 usleep(delay); |
102 } | 105 } |
103 | 106 |
104 /* f2 < f1 */ | 107 /* f2 < f1 */ |
105 while ((f1 - f2) > fstep) { | 108 while ((f1 - f2) > fstep) { |
106 f1 -= fstep; | 109 f1 -= fstep; |
107 ad9912_set_frequency(d, channel, f1); | 110 r = ad9912_set_frequency(d, channel, f1); |
111 if (r < 0) | |
112 return r; | |
108 usleep(delay); | 113 usleep(delay); |
109 } | 114 } |
110 | 115 |
111 /* final adjustment */ | 116 /* final adjustment */ |
112 ad9912_set_frequency(d, channel, f2); | 117 return ad9912_set_frequency(d, channel, f2); |
113 | |
114 return 0; | |
115 } | 118 } |
116 | 119 |
117 | 120 |
118 int ad9912_ramp_frequency(struct ad9912 *d, unsigned channel, double f, double fstep) | 121 int ad9912_ramp_frequency(struct ad9912 *d, unsigned channel, double f, double fstep) |
119 { | 122 { |