On 10/13/2014 04:24 AM, Sébastien Bourdeauducq wrote:
> On 08/12/2014 05:32 PM, Robert Jordens wrote:
>> n = core.coerce(1.2345*ns) # [n] = core.cycle
>> for i in range(1000):
>>     core.delay(n)
>> f = dds.coerce(345*MHz)
>> t = dds.coerce(core.coerce(1000*n, to=ns))
>> phi = dds.coerce(f*t, to=rad) # [f*t] = dds.ftw*dds.cycle
> 
> It's implementable right now as:
> 
> # n is RTIO cycle count (dimensionless int64)
> n = time_to_cycles(1.2345*ns)
> 
> for i in range(1000):
>     # cycles_to_time is exact (uses rational arithmetic)
>     # compiler optimizes to "now += n" (int64 operation)
>     delay(cycles_to_time(n))

> # ftw is raw int32 frequency tuning word
> ftw = self.dds.frequency_to_ftw(345*MHz)
> 
> # f is exact (rational) frequency in Hz
> f = self.dds.ftw_to_frequency(ftw)
> 
> # phi is in turns, rational number
> phi = 1000*cycles_to_time(n)*f

Looks good!
The numeric types do not seem to have units atached to them and no
typechecking is done on the units level. Doing
delay(dds.frequency_to_ftw(123*MHz)) would not fail/err. That is ok by me.

> When running on the device (running on the host in the interpreter is
> also possible), the transforms turn that into the following code before
> passing it to py2llvm (with 1GHz RTIO and DDS clocks):
> 
> now = int64(0)
> n = int64(1)
> for i in range(1000):
>     now += n
> frequency_to_ftw_return = 1481763717
> ftw = frequency_to_ftw_return
> ftw_to_frequency_return = ((ftw * Fraction(1000000000, 1)) / 4294967296)
> f = ftw_to_frequency_return
> phi = ((1000 * (n * Fraction(1, 1000000000))) * f)
> 
> The obvious performance optimization here is to have the constant
> folding transform work across statements.

The llvm optimizer passes should be able to do that, right?

> Since there is only one FUD sampling by the DDS chip every 8 RTIO/DDS
> cycles, this phase difference computation is correct only if "now" is
> increased by a multiple of 8 in the block of code.

You mean a multiple of 8 in total after the loop?

I would think it is correct in any case just that you can not change POW
(correctly) if now.microcycle != 0. Having known phase even for the
microcycles is valuable since then we can e.g. turn on and off a dds
pulse with microcycle phase accuracy using the rf switches.

Robert.
_______________________________________________
ARTIQ mailing list
https://ssl.serverraum.org/lists/listinfo/artiq

Reply via email to