Introduction
SiM3U1xx and
SiM3C1xx include the Current-to_Voltage Converter (IVC) module. The IVC module
allows current sourced from a pin (sunk externally) to be measured by SARADCn
modules on the device.
Function Description
The IVC module consists of two channels of
current-to-voltage conversion circuitry. Current is sourced from the IVC0.0 or
IVC0.1 pins, creating a voltage drop at the pin and the ADC input. A simplified
diagram of single channel of the IVC circuitry is shown in below Figure.
The IVC module has selectable full-scale current ranges of 1
mA to 6 mA, configurable in 1 mA steps. The transfer function of the IVC module
is a curve that is 0 V with a 0 mA input, and 1.65 V at full scale.
We need to set PB0.7 pin as analog if want to use IVC
function.
And set IVC0 as SARADC input channel.
We need a little math to calculate the current, here is the
equation.
Vout = (Vfullscale x code)/1023
Iin = Vout / slope
Where:
code = the left-justified 10 bit SARADC output code
Vfullscale =Full scale output, it 1.65V
Vout = IVC convert voltage output value
Iin = the current sunk externally from IVCn pin.
Slope = 275 mV/mA with condition input range 6mA
Here is the detailed register description for IVC0 registers
Code Implementation
We used AppBuilder
to generate basic code we need, and then added necessary code to make
temperature sensor works.
void CLKCTRL_setup_default_mode_clock_gates(void)
{
SI32_CLKCTRL_A_enable_apb_to_modules_0(SI32_CLKCTRL_0,
SI32_CLKCTRL_A_APBCLKG0_PB0 |
SI32_CLKCTRL_A_APBCLKG0_SARADC0);|
SI32_CLKCTRL_A_enable_apb_to_modules_1(SI32_CLKCTRL_0,
SI32_CLKCTRL_A_APBCLKG1_MISC1 |
SI32_CLKCTRL_A_APBCLKG1_MISC0);
}
2.
Configure the input range 6mA of the IVC
channel and enable the IVC channel.(gIVC0.c)
void IVC0_enter_default_mode_from_reset(void)
{
SI32_IVC_A_select_channel_0_range(SI32_IVC_0,
SI32_IVC_A_CONTROL_IN0RANGE_6_MA_VALUE);
SI32_IVC_A_enable_channel_0(SI32_IVC_0);
}
3.
Enable SARADC module; Timeslot0 channel is “IVC0.0
Output”; Output packing mode is “Lower half-word only”. And keep default
setting of reference GND select as “internal GND” and start of conversion
source as “On Demand by writing 1to ADBUSY” (gSARADC.c)
void SARADC0_enter_default_mode_from_reset(void)
{
SI32_SARADC_A_enable_module(SI32_SARADC_0);
SI32_SARADC_A_select_output_packing_mode_lower_halfword_only(SI32_SARADC_0);
SI32_SARADC_A_select_timeslot0_channel(SI32_SARADC_0,
16);
}
4.
Port bank configuration. PB0.0 and PB0.7 need to
be set as analog pin and skipped in crossbar.(gPB.c)
void pb_enter_default_mode_from_reset(void)
{
SI32_PBCFG_A_unlock_ports(SI32_PBCFG_0);
{
SI32_PBCFG_A_unlock_ports(SI32_PBCFG_0);
// PB0 Setup
SI32_PBSTD_A_set_pins_analog(SI32_PBSTD_0, 0x0081);
SI32_PBSTD_A_write_pbskipen(SI32_PBSTD_0, 0x2081);
// PB1 Setup
SI32_PBSTD_A_set_pins_push_pull_output(SI32_PBSTD_1, 0x0008);
SI32_PBSTD_A_write_pbskipen(SI32_PBSTD_1, 0x0008);
// Enable
Crossbar0 signals & set properties
SI32_PBCFG_A_enable_crossbar_0(SI32_PBCFG_0);
// PB2 Setup
SI32_PBSTD_A_set_pins_push_pull_output(SI32_PBSTD_2, 0x0C00);
SI32_PBSTD_A_set_pins_high_drive_strength(SI32_PBSTD_2, 0x0C00);
// Enable
Crossbar1 signals & set properties
SI32_PBCFG_A_enable_crossbar_1(SI32_PBCFG_0);
}
5.
Caculate IVC output voltage and input current.(mySARADC0.c)
void mySARADC0_current_convert_voltage(void)
{
uint32_t
voltage, current, tmp;
SI32_SARADC_A_start_conversion(SI32_SARADC_0);
while((0x20
& SI32_SARADC_A_read_fifostatus(SI32_SARADC_0)) == 0){
}
tmp =
SI32_SARADC_A_read_data(SI32_SARADC_0);
// IVC0 full
scale output is 1650 mV. SARADC is 10 bit, means max value is 1023
voltage = 1650
* tmp / 1023;
current =
voltage * 1000 / myIVC0_get_range_slope();
printf("The
Vout=%d mV, Current = %d uA \n",voltage, current );
}
Function validation
We use series-connected 1K resistors connect P0.7 (IVC0) pin to
GND, by choosing difference value ohm resistors; we can get difference current
output from P0.7 pin.
References
1.
SiM3U1xx/SiM3C1xx Reference Manual: downloadable
from the Silicon Labs web site at http://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support
Documents/TechnicalDocs/SiM3U1xx_SiM3C1xx_RM.pdf&src=DocumentationWebPart
2.
SiM3U1xx Data Sheet: downloadable from the
Silicon Labs web site at http://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support
Documents/TechnicalDocs/SiM3U1xx.pdf&src=DocumentationWebPart
No comments:
Post a Comment