This is the development sandbox for the DRV425EVM and its magnetic sensing.
Dependencies: mbed
Repository for the 2015 OhmBoyZ Capstone group.
main.cpp@17:9af7969cd74e, 2015-12-08 (annotated)
- Committer:
- aupu9659
- Date:
- Tue Dec 08 04:13:26 2015 +0000
- Revision:
- 17:9af7969cd74e
- Parent:
- 16:65b7b24fe260
Changed Units to Match. Correct Version as of 12/7
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 | 12:b9d71de8733d | 11 | printf("\n\rAnalogIn example\n\r"); |
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 | 16:65b7b24fe260 | 14 | meas *= 3.3; // Change the value to be in the 0 to 3.3 range (currently to V) |
Krabby127 | 12:b9d71de8733d | 15 | printf("meas = %fmV\n\r",meas*1000); // Print out raw measurement in terms of mV |
Krabby127 | 16:65b7b24fe260 | 16 | b=(meas-(3.3/2.0))/(4.0*12.2*100.0); // Based on equation 1 from DRV425EVM pdf (in T) |
Krabby127 | 16:65b7b24fe260 | 17 | //VVOUT [V] = B × G × RSHUNT × GAMP = B [mT] × 12.2 mA/mT × RSHUNT [Ω] × 4 [V/V] |
Krabby127 | 11:791839389530 | 18 | //VVOUT is with reference to REFIN |
Krabby127 | 12:b9d71de8733d | 19 | // 0 Tesla is VDD/2 |
Krabby127 | 3:7285d6ff672b | 20 | // 12.2 mA/mT |
Krabby127 | 16:65b7b24fe260 | 21 | printf("b = %fuT\n\r",b*1000000.0); // Print out b field measure in micro-Tesla |
aupu9659 | 17:9af7969cd74e | 22 | printf("b = %f Gauss\n\r", b*10000); // Output B field in Gauss |
Krabby127 | 12:b9d71de8733d | 23 | if (meas > 1.65) { // If the value is greater than 1.65V then switch the LED on |
Krabby127 | 12:b9d71de8733d | 24 | // positive magnetic field |
Krabby127 | 0:cbee968c2ec3 | 25 | led = 1; |
Krabby127 | 0:cbee968c2ec3 | 26 | } |
Krabby127 | 0:cbee968c2ec3 | 27 | else { |
Krabby127 | 0:cbee968c2ec3 | 28 | led = 0; |
Krabby127 | 0:cbee968c2ec3 | 29 | } |
davidcerrone | 9:4b887a45ac8c | 30 | wait(1); // wait 1 second |
Krabby127 | 0:cbee968c2ec3 | 31 | } |
Krabby127 | 0:cbee968c2ec3 | 32 | } |