Other Parts Discussed in Thread: MSP430F5529,
Hello Forums,
I am trying to get the MSP430F5529 on the LaunchPad mentioned (MSP-EXP430F5529LP) to read the voltage that is output from a 5A ACS712 current sensor. The sensor is power using the 5V and GND pins on the LaunchPad (in the 40-pin Booster Pack section). The sensor output can reach close to 5V when 5A of current flows through it, so I used a potential divider (with 3k resistors) at the sensor output to half the output voltage. The output of the divider is fed to P6.0 on the LaunchPad.
The relevant code I wrote for this is:
// Function name: ADC_Init // Purpose: Initializes and configures MSP430 ADC for conversion of ACS712 voltage reading to current // Inputs: none // Returns: none void ADC_Init(void){ REFCTL0 &= ~REFMSTR; //Set voltage reference control to ADC_12 registers //ADC Control Registers Setup ADC12CTL0 = ADC12SHT0_9|ADC12REFON|ADC12REF2_5V|ADC12ON; // Sample and hold time, adc reference generator on and set to 2.5V, adc on ADC12CTL1 = ADC12SHP; // SAMPCON signal source ADC12CTL2 = ADC12RES_2; // 12-bit resolution ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_0; // REF: Vref+ to MCU GND; Port 6 pin 0 P6DIR = 0x00; // P6.0 as input P6SEL |= 0x02; // P6.0 to be used by ADC ADC12CTL0 &= ~ADC12SC; // Clear 'Start Conversion' bit, to ensure conversion not started ADC12CTL0 |= ADC12ENC; } // Function name: Get_ACS712_Value // Purpose: Reads ACS 712 current sensor output voltage via ADC, then convert voltage to current // Inputs: none // Returns: Current value from ACS 712 Sensor void Get_ACS712_Value(void){ ADC12CTL0 |= ADC12SC; //Start ADC conv. while (ADC12CTL1 & ADC12BUSY){ // Poll busy bit waiting for conversion to complete __no_operation(); } unsigned int acs_voltage = ADC12MEM0 & 0x0FFF; // keep only low 12 bits float acs_volt2 = 2 * ( (float) acs_voltage) * (2.5 / 4095.0); bat_states.current = (acs_volt2 - 2.525) / 0.185; // x10 for 5V range on acs_712; x20 for 2.5V range on acs_712 }
Using this setup, and the code above, I am not getting the correct value. The value I am getting is -13.3A, which is way off, since it is out of the range of the sensor. Removing the sensor output from P6.0 gives a value of -13.6A. I am not sure where this offset is coming from, as it does not appear to be a calculation error.
I can verify that current sensor/potential divider setup works, and outputs approximately 1.25V for 0A through it, as expected. Connecting the sensor output to P6.0 does seem to drop the sensor output voltage to a very low value, around 0.03V.
Does anyone know what may be happening here?
Am I attempting to draw too much current from the LaunchPad, or is it a calculation error?
I did not configure P6.0 to use a pull-down resistor, so I am not sure what is causing this.
Regards