Test and Measurement Forum

ARDUINO ZERO AS BUFFER/ISOLATOR FOR PICOLOG DA LOGGERS - 3

Post discussions on projects you are working on

ARDUINO ZERO AS BUFFER/ISOLATOR FOR PICOLOG DA LOGGERS - 3

Postby Glovisol » Sun May 01, 2016 1:59 pm

DIRECT PROGRAMMING SAMD21 REGISTERS
FOR
OUTPUT PWM FREQUENCY / RESOLUTION OF ARDUINO ZERO


5. SKETCHES GENERAL
The sketches follow the structure outlined by the functional Blocks Diagram and work as soon as uploaded to Arduino Zero after all parameters (obtained by the PPWM Tool) are entered. Up to now the REFERENCE VOLTAGE has never been mentioned, but this parameter is essential to define the relationship between Arduino Zero inputs and PWM outputs. The standard Reference Voltage commands do not work and must be replaced as follows.

In place of AR_EXTERNAL:
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val;

In place of AR_INTERNAL1V0:
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; // 1.0V voltage reference

In place of AR_INTERNAL1V65:
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V

In place of AR_INTERNAL2V23:
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val;
// 1/1.48 VDDANA = 1/1.48* 3V3 = 2.2297. If driving PWM the corr. Factor 3300/12229.7 =1.48 must be used.

Please note that the system defaults to 3.3V Reference if one of the above expressions is not used. Also the Reference of 1.65V is half the Arduino Zero operating voltage of 3.3 V. Remember maximum voltage on any pin cannot exceed 3V and this rule also holds for the AREF pin!

PARAMETERS TO BE ENTERED
The following list only concerns the parameters required to PWM System set – up. The numbers shown are for clarification only.
• int PERX = 1023; //Resolution Parameter PER calculated by the PPWM tool.
• AR_INTERNAL2V23; //Sets Voltage Reference at 2229.7 mV.
• REG_GCLK_GENDIV = GCLK_GENDIV_DIV(D) | // Generic clock Divisor: calculated by PPWM tool.
• GCLK_GENDIV_ID(4); // Select Generic Clock (GCLK) 4.
• GCLK_GENCTRL_SRC_DFLL48M | // clock source selected by PPWM.
• GCLK_GENCTRL_ID(4); // Select GCLK4.
• const uint8_t CHANNELS = 6;
• const uint8_t pwmPins[] = { 2, 3, 4, 5, 6, 7 };
• GCLK_CLKCTRL_GEN_GCLK4 | // Select GCLK4
• REG_TCC0_CTRLA |= TCC_CTRLA_PRESCALER_DIV16 | // Prescaler Factor from the PPWM tool.
• REG_TCC1_CTRLA |= TCC_CTRLA_PRESCALER_DIV16 | // Prescaler Factor from the PPWM tool.



6. PRECISION VOLTAGE TRANSLATOR VREF. = 2229.7 mV

SYSTEM REQUIREMENTS
Most data acquisition equipment accepts analogue data from analogue output sensors in the range 0-1 V, 0-2V or 0-2.5V. DA Logger resolution is normally 8 to 12 Bit.

The Arduino ZERO Voltage Translator/DA Buffer accepts either analogue or digital sensor outputs and translates them to a voltage range suitable for the DA Logger input, while providing galvanic isolation between inputs and outputs.

Galvanic isolation is obtained by converting the generic input Data to a low frequency (500Hz approx.) PWM signal. The PWM drives an optocoupler (thereby providing input/output isolation) and the optocoupler output is processed by low pass filtering, or by the natural high frequency rejection of the DA Logger, to recover the original data for feeding the DA Logger’s inputs.

DATA CONVERSION & MANIPULATION
The sketch must keep track of input and output resolution. With:
int PERX = 1023; //Resolution Parameter PER calculated by the PPWM tool.
int BitX = log(PERX+1)/log(2); // Bits of PER parameter.

We compute the bits related to the calculated & required resolution PERX.

analogReadResolution(BitX); //This sets the INPUT resolution equal to the OUTPUT resolution. This can be done within limits, as maximum AnalogReadResolution is 12 Bits.

With:
float Vz_0 =(Vy_0 * Vref./PERX);
we recover the analogue voltage .

With Serial.print we show both the bits value and the analogue channel value.

With the expression:
REG_TCC0_CCB0 = corr. factor *Vy_0; //Output pin D2 e.g. corr. factor = 3300/2229.7 = 1.48.

With:
while(TCC0->SYNCBUSY.bit.CCB0);
we modulate the PWM output with the value read on pin A0. In other words the input of the PWM compare register is driven by our original analogue voltage input. It is important to remember that, by changing the value of PER, the Arduino Zero will follow with the new resolution, but, at the same time, the PWM frequency will change accordingly, while the duty cycle will stay the same.

Here below is copy of the PPWM Tool results.


DESCRIPTION.....................................DATA....................CALC

RESOLUTION (Analogue output function)......10,00
Dual Slope U/D count factor PER.......................................1.023,00
Clock Divisor, GENDIV............................3,00
Prescaler factor CTRLA, N......................16,00
GLK Clock frequency, Hz..............48.000.000,00
Timer frequency - Ft, Hz...........................................1.000.000,00
PWM frequency - Fpwm, Hz...............................................488,76
CCBx load for 50% duty cycle..............................................511,50

All the above is now exemplified by the uploaded sketch. The WORD text must be pasted to the Arduino IDE and it will start working as soon as uploaded.

In the next post the sketch based on standard external Vref = 2.5V will be uploaded. With this sketch it will be possible to use the same Shield, as developed for the previous work with Arduino UNO.
Attachments
Chan. 0 at 6mV input.png
Channel 0 PWM @ 6 mV input
Chan. 0 at 2200mV input.png
Channel 0 PWM @ 2200 mV input - freq. 488 Hz as calculated
Sketch_Translator_Vref_2229.7mV.doc
Buffer/Isolator sketch with Vref = 2229.7 mV
(39.5 KiB) Downloaded 46 times
Glovisol
Advanced User
Advanced User
 
Posts: 114
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests