Difference between revisions of "NU32: Using the MAX9918 current sensor"

From Mech
Jump to navigationJump to search
 
(13 intermediate revisions by one other user not shown)
Line 1: Line 1:
'''THIS PAGE REFERS TO A PRE-RELEASE VERSION OF THE NU32 PIC32 DEVELOPMENT BOARD. FOR INFORMATION, SAMPLE CODE, AND VIDEOS RELATED TO THE PRODUCTION VERSION (2016 AND LATER), AND TO THE CORRESPONDING BOOK "EMBEDDED COMPUTING AND MECHATRONICS WITH THE PIC32 MICROCONTROLLER," VISIT [[NU32|THE NU32 PAGE]].'''


Using the MAX9918 current sensor.
Using the MAX9918 current sensor.

[[Image:NU32_MAX9918.jpg|thumb|200px|The MAX9918 current sensor breakout board|center]]


== Overview ==
== Overview ==

[[Media:MAX9918.pdf|Datasheet]]


The MAX9918 is a bi-directional current-sense amplifier.
The MAX9918 is a bi-directional current-sense amplifier.
<BR>


[[Image:MAX9918.png|thumb|600px|center]]
Image
<BR>


By placing a small resistance in series with a load, a small voltage is generated across the "current sense" resistor that is proportional to the current through the load. The voltage is small so that most of the supply voltage is still across the load. The MAX9918 amplifies the small voltage, and the output can be read using the ADC in a microcontroller and interpreted as the current through the load.
By placing a small resistance in series with a load, a small voltage is generated across the "current sense" resistor that is proportional to the current through the load. The voltage is small so that most of the supply voltage is still across the load. The MAX9918 amplifies the small voltage, and the output can be read using the ADC in a microcontroller and interpreted as the current through the load.
Line 18: Line 27:
To set the voltage gain the MAX9918 will apply to the voltage read across the current sense resistor, place a resistance R1 between REF and FB (pin 6) and R2 between FB and output. The voltage gain will be (1 + R2 / R1).
To set the voltage gain the MAX9918 will apply to the voltage read across the current sense resistor, place a resistance R1 between REF and FB (pin 6) and R2 between FB and output. The voltage gain will be (1 + R2 / R1).


The output voltage is then 1.65 [V] + (I [A] * 0.015 [Ohm] * gain).
== Library Functions ==
[[Media:NU32SerialExample.zip | This code]] How to get the count

The functions are:
*void NU32_Initialize(void) - enables UART1 and UART4 at 115200 baud. UART4 starts with the interrupt at priority level 3, UART1 starts with no interrupt enabled
*void NU32_EnableUART1Interrupt(void) - enables the UART1 interrupt
*void NU32_WriteUART1(const char *) - call with the character array you wish to send, make the array with sprintf()
*void NU32_ReadUART1(char *, int) - call with the array you want to read into, and the maximum size of the array. The code will wait at this function and buffer all characters received until you send a '\r' or '\n' (by pressing [enter] on your keyboard)

NU32Example.c in the .zip file above demonstrates how to use the functions.


[[Image:MAX9918_sch.png|thumb|400px|center]]
== Sample Code ==


== Wiring ==
To initialize the serial communication, call NU32_Initialize(), :
[[Image:TB6612andMAX9918_wireup.png|thumb|600px|center]]


== Calibration ==
<pre>
You should calibrate your MAX9918 circuit and note in your code what current the output voltage corresponds to.
NU32_Initialize();
</pre>


Note the output voltage when zero current passes through the current-sense resistor.
To write a string to the computer, use NU32_WriteUART1(charArray). The special characters '\r' and '\n' are carriage return and newline. Using them together puts the cursor on the next line.


Build a circuit that will pass positive current through the current-sense resistor (the RS+ voltage > the RS- voltage). Try to get 2 different values of current through, as large as you can, without burning the resistor you are using to create the current (remember the resistors in your kit are 0.25W). Note the output voltages of the MAX9918.
<pre>
NU32_WriteUART1("\r\nHello World!\r\n");
</pre>


Do the same for negative currents, and make a plot of the results. Note the slope and use it in your microcontroller code to convert the voltage it reads from the MAX9918 to the current through the load.
To write a string with the value of a variable in it, use sprintf(charArray,"%d") and NU32_WriteUART1(charArray).


== More Information ==
== More Information ==

Latest revision as of 06:37, 16 January 2016

THIS PAGE REFERS TO A PRE-RELEASE VERSION OF THE NU32 PIC32 DEVELOPMENT BOARD. FOR INFORMATION, SAMPLE CODE, AND VIDEOS RELATED TO THE PRODUCTION VERSION (2016 AND LATER), AND TO THE CORRESPONDING BOOK "EMBEDDED COMPUTING AND MECHATRONICS WITH THE PIC32 MICROCONTROLLER," VISIT THE NU32 PAGE.


Using the MAX9918 current sensor.

The MAX9918 current sensor breakout board

Overview

Datasheet

The MAX9918 is a bi-directional current-sense amplifier.

MAX9918.png


By placing a small resistance in series with a load, a small voltage is generated across the "current sense" resistor that is proportional to the current through the load. The voltage is small so that most of the supply voltage is still across the load. The MAX9918 amplifies the small voltage, and the output can be read using the ADC in a microcontroller and interpreted as the current through the load.

Details

The MAX9918 breakout board brings out all of the pins of the MAX9918 to the breadboard. The chip runs on 5V (on VCC, pin 8) and GND (pin 4). Put the SHD pin (pin 3) high (5V) to have the chip operate.

A 0.015 Ohm current-sense resistor has been soldered between RS+ (pin 1) and RS- (pin 2), rather than giving you a through-hole resistor for your breadboard (the contacts of the breadboard have more resistance than 0.015 Ohm!)

When zero current is going through the current-sense resistor, the output (pin 5) will be the voltage applied to REF (pin 7). Put 1.65V on REF using a voltage divider of 10k resistors between 3.3V and GND.

To set the voltage gain the MAX9918 will apply to the voltage read across the current sense resistor, place a resistance R1 between REF and FB (pin 6) and R2 between FB and output. The voltage gain will be (1 + R2 / R1).

The output voltage is then 1.65 [V] + (I [A] * 0.015 [Ohm] * gain).

MAX9918 sch.png

Wiring

TB6612andMAX9918 wireup.png

Calibration

You should calibrate your MAX9918 circuit and note in your code what current the output voltage corresponds to.

Note the output voltage when zero current passes through the current-sense resistor.

Build a circuit that will pass positive current through the current-sense resistor (the RS+ voltage > the RS- voltage). Try to get 2 different values of current through, as large as you can, without burning the resistor you are using to create the current (remember the resistors in your kit are 0.25W). Note the output voltages of the MAX9918.

Do the same for negative currents, and make a plot of the results. Note the slope and use it in your microcontroller code to convert the voltage it reads from the MAX9918 to the current through the load.

More Information

NA