5

I am working on a project where I need to measure an oscillating magnetic field that oscillates at a frequency of 100 Hz. For this reason, I am using a Hall sensor. I programmed the Hall sensor to operate in "500 Hz continuous measurement node" and I generate the 100 Hz magnetic field using a linear amplifier with an air coil and a function generator as signal source.

When I compute the DFT (250 samples at 500 Hz, e.g. a measurement of 0.5 s duration), I get the following result:

enter image description here

I do get a peak at 100 Hz, as expected. However, I also see a lot of "sidelobes" that are spaced in multiples of 10 Hz from the main peak. I also observed the following:

  • The side peaks also occur when I change the magnetic field frequency to 50 Hz and 75 Hz and they also seems to be spaced at 10 Hz intervals. When I set the magnetic field frequency to 500 Hz, I see a constant signal with a 10 Hz sinusoid superimposed. When I set the number of samples in the frame from 250 to 200 or from 250 to 500 (at 500 Hz sampling again), I also notice the side peaks spaced at 10 Hz.)
  • I previously used a different Hall sensor, that sampled at 2 kHz. When I use this sensor to record a 0.5 s frame I can see a single peak in the DFT, so I assume that the magnetic field does not have the side peaks in reality.

Does anyone have an idea on how to debug this?

Edit: Implementation details

I implemented the communication to the sensor in the following way:

  • I set up the sensor to "500 Hz continuous measurement mode"
  • I have a 500 Hz interrupt on the uC. This interrupt triggers the reading of the sensor magnetic field value. This is done by first writing the address to be read to the sensor and then conducting an I2C read operation. I monitor the timing of this interrupt with a GPIO on an oscilloscope and the interrupt timing is very stable at 500 Hz as shown on the oscilloscope.
  • The I2C frequency was set to 200 kHz.

I could also use the "single measurement mode" and see if that improves the situation.

Edit2: Issue now seems resolved

I think I was now able to resolve this issue by using the "single measurement mode" instead of the "500Hz continuous measurement mode" of the sensor. The implementation now does the following:

  1. Set a 500Hz interrupt on the uC
  2. uC sends trigger signal to sensor to start measurement when interrupt occurs.
  3. While sensor measures new value, uC reads old value.

This gives me the following result:

DFT for different sensor timing

Mantabit
  • 343
  • 1
  • 10
  • Hello, the input is a sine wave, I checked this using a current probe with oscilloscope. – Mantabit Jan 12 '23 at 08:54
  • Well what happens every 100ms in the system? Debug prints? Have you checked the status register if it indicates a overflow if data was not read when it was ready and it was skipped? Which I2C frequency you use and how do you poll for data? Does some interrupt pin indicate delays in data availbility every 100ms? – Justme Jan 12 '23 at 09:04
  • you should use a "window" weighting because measuring only 5 cycles ... Classical function generator? – Antonio51 Jan 12 '23 at 09:12
  • 2
    How exact are your 100 and 500 Hz? For instance, if the '500 Hz' sampling is really 490 Hz, then harmonics of the 100 Hz signal would be aliased to 10 Hz – Neil_UK Jan 12 '23 at 09:14
  • I doubt that it is aliasing, as the sidelobs are also 10 Hz for different field frequencies. And aliases wouldn't so nicely and symmetrically fall off from the main lobe. – tobalt Jan 12 '23 at 09:23
  • @Antonio51 although a window won't hurt, this **isn't** scalloping spectral spread (which could just "blur" the main lobe) – tobalt Jan 12 '23 at 09:25
  • @Mantabit please, explain "how" samples are taken ... – Antonio51 Jan 12 '23 at 09:37
  • Hello and thanks for all of your replies, I edited the post to go into more detail on how the sampling is done. Right now there isn't really a synchronization between the Hall Sensor and the function generator. I actually used a similar technique for another hall sensor which worked quite well (I didn't see any sidelobes with the other sensor), however, for the other sensor I triggered the measurement manually via I2C from the uC. I'll try to solve this issue by triggering the sensor manually from the uC by using "single measurement mode", I'll also check the status register. – Mantabit Jan 12 '23 at 09:49
  • @Justme, I think you are right, I monitored the status register now and the Dataoverrun flag is raised from time to time. I will try to fix the timing of my code then... – Mantabit Jan 12 '23 at 09:57
  • If your sampled signal is Bz then, why would you expect not to see sidelobes; it's an imperfect sampled sinewave. A perfect sinewave has been in existence since the dawn of time and you have a very imperfect sample lasting 250 ms. I can't see how you would expect it to have no side-lobes. – Andy aka Jan 12 '23 at 10:02

2 Answers2

16

If the sensor is set to 500 Hz sampling, and you have a MCU timer also set to 500 Hz to read the results, this is never going to work, because nothing is ever exact, especially devices with internal clocks may have large tolerances.

In your case the difference between sampling rate and MCU os such that sensor samples faster and MCU fails to read every sample, about 10 samples per second is skipped.

You must change the system to be able to read every sample there is available. The sensor has a pin for signaling when data is available, and the MCU can be made to react to it one way or another.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • I think this is the correct answer, triggering each sample manually from the uC seems to resolve this issue. Thanks! – Mantabit Jan 12 '23 at 10:28
2

Too long for a comment. So posting as an answer, but please downvote if wrong ( I didnt think too deeply).

I guess it could be some special form of timing jitter of your sensor:

The 500 Hz could be obtained by 50 samples at a slightly higher rate, followed by a slightly longer pause and another 50 slightly faster samples.

I suppose that would explain your observations.

You can check it, if you don't modulate the field at all: In that case you should not observe a sinusoidal modulation in the field.

tobalt
  • 18,646
  • 16
  • 73