This is the development sandbox for the DRV425EVM and its magnetic sensing.
Dependencies: mbed
Repository for the 2015 OhmBoyZ Capstone group.
main.cpp@9:4b887a45ac8c, 2015-12-01 (annotated)
- Committer:
- davidcerrone
- Date:
- Tue Dec 01 18:29:38 2015 +0000
- Revision:
- 9:4b887a45ac8c
- Parent:
- 6:2f0942f33585
- Child:
- 10:3f9fbc127abb
Changed offset to mV
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Krabby127 | 0:cbee968c2ec3 | 1 | #include "mbed.h" |
Krabby127 | 0:cbee968c2ec3 | 2 | #include <math.h> |
Krabby127 | 0:cbee968c2ec3 | 3 | |
Krabby127 | 0:cbee968c2ec3 | 4 | AnalogIn analog_value(A0); |
Krabby127 | 0:cbee968c2ec3 | 5 | |
Krabby127 | 0:cbee968c2ec3 | 6 | DigitalOut led(LED1); |
Krabby127 | 0:cbee968c2ec3 | 7 | |
Krabby127 | 0:cbee968c2ec3 | 8 | int main() { |
Krabby127 | 0:cbee968c2ec3 | 9 | float meas; |
Krabby127 | 0:cbee968c2ec3 | 10 | float b; |
Krabby127 | 0:cbee968c2ec3 | 11 | printf("\nAnalogIn example\n"); |
Krabby127 | 0:cbee968c2ec3 | 12 | while(1) { |
Krabby127 | 0:cbee968c2ec3 | 13 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
Krabby127 | 0:cbee968c2ec3 | 14 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range (currently to mV) |
Krabby127 | 1:d901038c4bd2 | 15 | printf("meas = %fmV\n\r",meas); // Print out raw measurement in terms of mV |
davidcerrone | 9:4b887a45ac8c | 16 | b=((meas-3.3/2.0*1000)/(4.0*12.2*100.0)); // Based on equation 1 |
Krabby127 | 5:760f85b3f309 | 17 | //VVOUT [V] = B × G × RSHUNT × GAMP = B [mT] × 12.2 mA/mT × RSHUNT [Ω] × 4 [V/V] |
Krabby127 | 5:760f85b3f309 | 18 | //0 Tesla is VDD/2 |
Krabby127 | 3:7285d6ff672b | 19 | // 12.2 mA/mT |
Krabby127 | 5:760f85b3f309 | 20 | printf("b = %f Gauss\n\r",b); // Print out b field measure in milliTesla |
Krabby127 | 6:2f0942f33585 | 21 | printf("B = %fuT\n\r", b*100.0); // Output B field in micro-Tesla |
Krabby127 | 1:d901038c4bd2 | 22 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
Krabby127 | 1:d901038c4bd2 | 23 | // greater than 410 microGauss [40 mT] |
Krabby127 | 0:cbee968c2ec3 | 24 | led = 1; |
Krabby127 | 0:cbee968c2ec3 | 25 | } |
Krabby127 | 0:cbee968c2ec3 | 26 | else { |
Krabby127 | 0:cbee968c2ec3 | 27 | led = 0; |
Krabby127 | 0:cbee968c2ec3 | 28 | } |
davidcerrone | 9:4b887a45ac8c | 29 | wait(1); // wait 1 second |
Krabby127 | 0:cbee968c2ec3 | 30 | } |
Krabby127 | 0:cbee968c2ec3 | 31 | } |