This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMAG5273: Threshold calculation for negative mT

Part Number: TMAG5273

Just a bit confused on how to set thresholds for negative values (aka values which are negative in mT). I was using the sensor to detect the opening and closing of case. I measured the Y value of the sensor and output it through uart when the case is closed and when its opened. When the case is closed i got a value of 63776 (-4.29 mT i calculated) and when open i got 65104 (-1.05 mT) and therefore im trying to add a threshold between these value so somewhere around -2mT and just change MAG_THR_DIR bit in the sensor config 2 register. I'm not sure what im doing wrong but can't seem detect the opening and closing when i set the threshold to -2 mT. Maybe i'm getting the calculation wrong. Can someone help me with this. Thanks

  • Hello Roshan,

    Thanks for considering to use Texas instruments.  From the values given, I presume you are using the A1 device with the x_y_range bit set to 1 for the +-80mT range. Per the datasheet, I would try the following to program the device to trip at -2mT.  I would start with calculating the threshold for 2mT.  To get this I assume X_Y_RANGE =1, and I would take 2mT*128/(40*(1+X_Y_RANGE) = X_THR_CONFIG =3.2.  As X_THR_CONFIG needs to be an integer between 1 and 128, we need to round this number. 3 equates to about 1.875mT and 4 equates to 2.5mT  (you could get a little closer if you made the range 40mT, x_y_range=0).  Presuming we proceeded with 3 (1.875mT threshold), lets now get the -1.875mT threshold.  Since we are considering a number with 8 bits (including leading 0s), 3 can be written 0000 0011, to get the 2s complement, we invert this to get 1111 1100 and then add 1 to get 1111 1101 = 253.  Is this the value you have been entering?

  • Hi Patrick, thanks for your reply, i was trying a different value, but i did try this value and it was seems trigger but when changing the direction of trigger aka MAG_THR_DIR it doesn't seem to behave correctly. So my intention is when i open the case, the flux value drops, then change the value of MAG_THR_DIR to 0 so the device waits until the flux goes above that threshold, i then set MAG_THR_DIR to 1 so then the device waits until the flux drops below the threshold. Would this be the correct way to think of it, or is it different because i am now dealing with negative flux

  • Hey Roshan,

    Can you provide a diagram of what you are trying to do, such as what you expect the field to look like and how you expect the interrupt to react?

  •   This is sort of what i want to expect, sorry this is just a rough sketch, but every time the threshold is crossed i want to change the direction of the threshold check each time the threshold is crossed. Hope this is good.

  • Hello Roshan,

    Thank you for providing that.   I think I have a better understanding of what you are trying to do now.  Below I have a picture of what I think you desire versus what the device can do. I think you will need to write a function for the microcontroller communicating with the device to track threshold crossing interrupts and update the MAG_THR_DIR setting.  Presuming a person is open and closing the case, I imagine the duration between open and closing will be on the order of seconds or 100s of miliseconds, which I think would give you adequate time to change the MAG_THR_DIR setting without missing the threshold crossing.