Hello,
using the NHS3152 I need to deliver a given current to a load ( an LED so that I can control its brigthness).
I'm using pad PIO0_3, the current it sinks can be chosen using ILO and IHI values coded on 8 bits.
Below is a sample code (I provide current_low and current high values corresponding to the currrent I want through the load when PIO0_3 is set low and high respectively).
I seems the current values can only be integers, i.e; 1, 2, 3 ..mA.
Here are some measurments (current_low = 0, 0.1, 0.2, 0.5, ...1, 1.1, 1.2, ... 2, mA etc) while current_high is 0). The fractional part of the current is not taken into account; Why?
I though Imax =20mA, then current increment is 20/256=0.078mA
Thanks
Chip_IOCON_Init(NSS_IOCON); /* in general done at top main*/ Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_PIO0_3, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE | IOCON_CDRIVE_PROGRAMMABLECURRENT | IOCON_ILO_VAL(current_low * 255 / 20) /* current_min mA low */ | IOCON_IHI_VAL(current_high * 255 / 20) /* current_max mA high */ ); Chip_GPIO_SetPinDIROutput(NSS_GPIO, 0, IOCON_PIO0_3); Chip_GPIO_SetPinOutLow(NSS_GPIO, 0, IOCON_PIO0_3); //to get current_low mA through the load
Solved! Go to Solution.
Hi CyrilBZH,
Truncation can be avoided by expressing the wanted current as an integer in micro Amperes units.
For instance 0.5(mA) becomes 500(uA)
The scale factor for the CDRIVE is than (X* 255)/20000.
(Note that the order of the integer operations is important: the multiplication has to be done first, division second)
The example below sets the low and high currents to 0.5mA and 3.5mA.
int current_low_uA = 500; // 0.5mA
int current_high_uA = 3500; // 3.5mA
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_PIO0_3, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE | IOCON_CDRIVE_PROGRAMMABLECURRENT
| IOCON_ILO_VAL((current_low_uA * 255) / 20000) /* current_min uA low */
| IOCON_IHI_VAL((current_high_uA * 255) / 20000) /* current_max uA high */
);
Kind regards,
Patrick
Hi CyrilBZH,
Truncation can be avoided by expressing the wanted current as an integer in micro Amperes units.
For instance 0.5(mA) becomes 500(uA)
The scale factor for the CDRIVE is than (X* 255)/20000.
(Note that the order of the integer operations is important: the multiplication has to be done first, division second)
The example below sets the low and high currents to 0.5mA and 3.5mA.
int current_low_uA = 500; // 0.5mA
int current_high_uA = 3500; // 3.5mA
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_PIO0_3, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE | IOCON_CDRIVE_PROGRAMMABLECURRENT
| IOCON_ILO_VAL((current_low_uA * 255) / 20000) /* current_min uA low */
| IOCON_IHI_VAL((current_high_uA * 255) / 20000) /* current_max uA high */
);
Kind regards,
Patrick