12 bit resolution from the slow analog outputs with SCPI?

Applications, development tools, FPGA, C, WEB
Post Reply
rstaacke
Posts: 3
Joined: Mon Jun 27, 2016 2:53 pm

12 bit resolution from the slow analog outputs with SCPI?

Post by rstaacke » Tue Aug 23, 2016 3:51 pm

Hi,

I'm using the Red Pitaya as a current controller for a laser switch. One of the slow analog pins should give me a voltage between 1 V and 1.43 V to control the gate voltage of a FET. I used python with the SCPI server to manage that. Everything is working fine, but instead of a 12 bit resolution (should be equal to 1.8 V/4096~0.44 mV) I got an resolution of approximately 7.3 bit (~11 mV). As described here this seems to be the normal way the DAC is working. But how can I access the 12 bit over SCPI? I couldn't find any implementation for the full 12 bit for the analog pin in the SCPI server files. Is there a simple way to extend the SCPI commands to get the 12 bit?

Greetings,

Robert

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: 12 bit resolution from the slow analog outputs with SCPI

Post by Nils Roos » Wed Aug 24, 2016 6:27 pm

You'll have to modify the underlying librp.so to get access to the full resolution. The scpi-server just takes the arguments to "ANALOG:PIN" and calls the rp_ApinSetValue() from the RP api.

The api then truncates the float argument for the output voltage to the 0-156 range for the slow DAC. This happens in rp_AOpinSetValue(). This is the place to put additional code that encodes the missing 4bit resolution into 16bit as outlined in the description you linked. Then you must adapt rp_AOpinSetValueRaw() to forward the additional information to the hardware.

rstaacke
Posts: 3
Joined: Mon Jun 27, 2016 2:53 pm

Re: 12 bit resolution from the slow analog outputs with SCPI

Post by rstaacke » Tue Sep 20, 2016 10:33 am

Hi Nils,

thanks for your reply. I tried to understand the API and for me it looks like rp_ApinSetValue() calls rp_AOpinSetValue() which converts my voltage send from the SCPI server to a bit value 0-ANALOG_OUT_MAX_VAL_INTEGER. Where ANALOG_OUT_MAX_VAL_INTEGER is defined in analog_mixed_signals.h as 156. Then rp_AOpinSetValue() calls rp_AOpinGetValueRaw() and apply a 8bit (ANALOG_OUT_MASK) and left shift it by 16. The shift would mean that i get a 24 bit number which is transferred to the hardware with iowrite32().
If I'm right until here, would change rp_AOpinGetValueRaw() so, that the last 16 zeros after the left shift represent the fine grading of my output voltage?

Greetings,
Robert

rstaacke
Posts: 3
Joined: Mon Jun 27, 2016 2:53 pm

Re: 12 bit resolution from the slow analog outputs with SCPI

Post by rstaacke » Thu Sep 29, 2016 7:29 am

So everything is working well and I get 11.3 Bits of resolution out of the slow analog outputs. For everyone who wants to change the API for 11.3 Bit, I changed some lines in rp.c:

Code: Select all

int rp_AOpinSetValueRawFine(int unsigned pin, uint32_t value, uint32_t fine) {
    if (pin >= 4) {
        return RP_EPN;
    }
    if (value > ANALOG_OUT_MAX_VAL_INTEGER) {
        return RP_EOOR;
    }
    uint32_t fine_bit=0;
    for (int i=0; i<fine; ++i) {
        fine_bit = (fine_bit << 1) | 1;          
    }      
    iowrite32((((value & ANALOG_OUT_MASK) << ANALOG_OUT_BITS) | fine_bit), &ams->dac[pin]);
    return RP_OK;
}
int rp_AOpinSetValueRaw(int unsigned pin, uint32_t value) {
    return rp_AOpinSetValueRawFine(pin,value,0);
}
int rp_AOpinSetValue(int unsigned pin, float value) {
    uint32_t value_raw = (uint32_t) (((value - ANALOG_OUT_MIN_VAL) / (ANALOG_OUT_MAX_VAL - ANALOG_OUT_MIN_VAL)) * ANALOG_OUT_MAX_VAL_INTEGER);
    uint32_t value_fine = (uint32_t) (ANALOG_OUT_BITS * ((float) (((value - ANALOG_OUT_MIN_VAL) / (ANALOG_OUT_MAX_VAL - ANALOG_OUT_MIN_VAL))
             * ANALOG_OUT_MAX_VAL_INTEGER) - value_raw ));
    return rp_AOpinSetValueRawFine(pin, value_raw, value_fine);
}
I didn't know if some other methods can call rp_AOpinSetValueRaw, so rp_AOpinSetValueRaw is now calling rp_AOpinSetValueRawFine with 0/16 of the fine value. Is there a reason why the PMW is running a clock only from 0-156 and not to 256? What is the reason for not using the fine values of rp_AOpinSetValueRaw? Maybe this can be adapted to the code.

Greetings,
Robert

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: 12 bit resolution from the slow analog outputs with SCPI

Post by Nils Roos » Thu Sep 29, 2016 7:32 pm

Is there a reason why the PMW is running a clock only from 0-156 and not to 256?
Yes, the PWM logic is clocked at 250MHz and with the 16 cycles required for the fine part of the resolution, you have 156 periods (of 16 cycles each) to arrive at the desired 100kSps.
What is the reason for not using the fine values of rp_AOpinSetValueRaw?
Procrastination? Maybe coupled with a lack of an immediate good idea how to transform the 4bits to a 16bit pattern? Who knows.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 98 guests