Commit de71dd4e authored by Holger Witsch's avatar Holger Witsch

New approach to timestep and its multiplier

parent c4e9ab6e
......@@ -60,7 +60,7 @@
#include <time.h>
#include <w_attribute.h>
#include <stdlib.h>
#include <cmath> // floor and ceil
#include <cmath> // floor and ceil and round
#include <iostream>
#include <algorithm>
......@@ -1657,16 +1657,15 @@ void Fpga::write_AcquisitionParameters(Tango::WAttribute &attr)
// number of cycles
number_of_waveforms_to_average = attr_NumberWaveforms_read[0] = w_val[2];
unsigned int tstmult;
unsigned int newfreq;
// possibly the requested frequency can not be used. The function will raise an exception if
// the combination of frequency and samples is impossible.
timestep_multiplier = attr_TimestepMultiplier_read[0] = Fpga::checkAcquisitionParameters(frequency);
// write multiplier to attribute
// Tango::MultiAttribute *m_attr = get_device_attr();
// Tango::WAttribute &w_att = m_attr->get_w_attr_by_name("TimestepMultiplier");
Tango::MultiAttribute *m_attr = get_device_attr();
Tango::WAttribute &w_att = m_attr->get_w_attr_by_name("TimestepMultiplier");
// this line throws : Incompatible attribute type, expected type is : Tango::DevVarLongArray (even for single value)
// w_att.set_write_value(timestep_multiplier);
w_att.set_write_value(timestep_multiplier);
DEBUG_STREAM << "TimeStepMultiplier: " << timestep_multiplier << endl;
DEBUG_STREAM << "Delay between samples: " << timestep_multiplier * timestep_resolution << endl;
......@@ -2588,35 +2587,61 @@ void Fpga::filename()
/*
* Check, if there is a possible combination of frequency, timestep multiplier and number of samples.
*
* returns: returns single integer, -1 if there is no possible combination of frequency and number
* returns: returns single integer, -1 if there is no possible combivm trnation of frequency and number
* of samples or a possible frequency for this number of points. Frequency is the more important
* parameter (dixit P. Thompson Dec. 2018)
*/
int Fpga::checkAcquisitionParameters(unsigned int freq)
{
DEBUG_STREAM << "Fpga::checkAcquisitionParameters(" << freq << ", " << timestep_resolution << ", " << samples_per_waveform << ") entering... " << endl;
double tstepres = timestep_resolution * 1e-9;
unsigned int nsamples = samples_per_waveform;
int tsmult = 1; // this value should not be given by the client, as it is depending on the given values !!!!
double tmpfreq = 1. / (tstepres * nsamples * tsmult);
int possfreq = lround(tmpfreq);
unsigned int timestep = timestep_resolution;
unsigned int samples = samples_per_waveform;
int multiplier = 0;
double wavelength = 1 / freq;
DEBUG_STREAM << "Fpga::checkAcquisitionParameters(" << freq << ", " << samples << ", " << samples_per_waveform << ") entering... " << endl;
double tmpmult;
tmpmult = double(possfreq) / double(freq);
double timeBetweenSamples = wavelength / samples * 1e9;
if (abs(tmpmult - double(tmpmult)) > 0.003)
{
sprintf(err, " %s: Frequency refused : (%d Hz)!", get_name().c_str(), freq);
DEBUG_STREAM << err << endl;
Tango::Except::throw_exception((const char *)"Fpga::error", (const char *)err, (const char *)"Fpga::checkAcquisitionParameters");
// return tmpmult; can I return sth when trhowing an exception ?
// check if this is not too much
if (timeBetweenSamples < 25) {
// raise Exception("too small") # %g < %g" % (timeBetweenPoints, timestep))
Tango::Except::throw_exception((const char *)"Fpga::error", (const char *)err, (const char *)"Fpga::checkAcquisitionParameters: time betweeen samples too short");
}
unsigned int i, n, lasti;
double rest = double(timeBetweenSamples - int(timeBetweenSamples));
n = int(timeBetweenSamples); // work in nano seconds
for (i=1; i < n + 1; i ++ ) {
if (!(n % i)) {
if (i > 32) {
break;
}
lasti = i; // last value, this one's too big
}
}
timestep = lasti;
multiplier = int(timeBetweenSamples / timestep);
DEBUG_STREAM << "TimeStep for " << freq << " Hz and " << samples << "samples" << "are: " << timestep << "ns * " << \
multiplier << ", leaving " << rest * samples << "ns per wavelength unused. ****" << endl;
if (multiplier < 1 || multiplier > pow(2,27)) {
Tango::Except::throw_exception((const char *)"Fpga::error", (const char *)err, (const char *)"Fpga::checkAcquisitionParameters: multiplier too big");
}
return multiplier;
// if (abs(tmpmult - double(tmpmult)) > 0.003)
// {
// sprintf(err, " %s: Frequency refused : (%d Hz)!", get_name().c_str(), freq);
// DEBUG_STREAM << err << endl;
// Tango::Except::throw_exception((const char *)"Fpga::error", (const char *)err, (const char *)"Fpga::checkAcquisitionParameters");
// // return tmpmult; can I return sth when trhowing an exception ?
// }
// take over the calculated multiplier
timestep_multiplier = attr_TimestepMultiplier_read[0] = tmpmult;
// DEBUG_STREAM << "\n\n\n\n ************ With frequency " << freq << " possible Num points: " << \
// nsamples << " and multiplier: " << timestep_multiplier << "\n\n\n\n" << endl;
return tmpmult;
// // take over the calculated multiplier
// timestep_multiplier = attr_TimestepMultiplier_read[0] = tmpmult;
// // DEBUG_STREAM << "\n\n\n\n ************ With frequency " << freq << " possible Num points: " << \
// // nsamples << " and multiplier: " << timestep_multiplier << "\n\n\n\n" << endl;
// return tmpmult;
}
/*----- PROTECTED REGION END -----*/ // Fpga::namespace_ending
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment