Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading out sensor-values #2

Open
j-protex opened this issue Mar 22, 2018 · 6 comments
Open

Reading out sensor-values #2

j-protex opened this issue Mar 22, 2018 · 6 comments

Comments

@j-protex
Copy link

Hey there,

I was really excited when I found your code for sampling at a constant rate and even more excited when I got the "SdFatSDIO_low_latency_logger.ino"-example running for my purpose.
I (simply) want to log the signal of a PIR-sensor (motion-sensor). So I actually just changed the ISR-part like this (storage is my struct for the data that has to be saved):

void captureData() { storage.logTime = micros(); for (uint8_t i = 0 ; i < 2 ; i++) { storage.data[i] = analogRead(i); } logEntry( {storage.logTime, storage.data[0], storage.data[1]}); }

Now, when I looked at the logged data, the sample rate was perfectly constant at 1 kHz. But although I made a test measurement inside an empty room (where there was no movement at all) there were these strange peaks in the signal:
peaks_pir

These peaks seem to appear just when the Teensy is actually writing. While the code was running I simultaneously measured the signal with an oscilloscope. During the first 20 secs, where the Teensy is just waiting until it is mounted, the signal was constant and the peaks began to appear right after the start of the saving process.

The rate of peaks (from one peak to the next) is about 800 mHz, or every 1.2 seconds.

Any ideas, how to avoid the peaks?

Best regards and thank you for your time!

@tni
Copy link
Owner

tni commented Mar 22, 2018

If I had to guess, you are seeing power fluctuations. SD cards have a power consumption in the order of microwatts when they sleep, a write may draw several hundred mA (cards vary a lot). That's a rather massive load step for the voltage regulator.

The analog reference is by default using the 3.3V supply voltage, so any supply voltage fluctuation will show up in measurements.

Try using the internal voltage reference, if things look different. Check the AREF pin, if the 3.3V analog reference voltage is stable.

@j-protex
Copy link
Author

Thank you for the fast response!
I measured the 3.3V pin and couldn't see any large changes. But without changing the analog reference (= using the 3.3V supply) there were peaks in AREF correlating with the sensor signal peaks.

I don't really understand what you mean.. do you think having an external AREF for analogRead could improve the signal? For example using another voltage source?

@tni
Copy link
Owner

tni commented Mar 22, 2018

Since you are seeing AREF fluctuations that are correlated with the signal fluctuation, yes, an external reference would help a lot.

If you look at the Teensy schematic:
https://www.pjrc.com/teensy/schematic.html
VREFH (external reference input) is fed from 3.3V via a 470Ohm resistor. You either need to perform micro-surgery to feed VREFH from a stable voltage (and disconnect it from 3.3V) or you can connect a very low impedance reference to AREF (e.g. a shunt reference between AREF and ground).

Teensy has a 1.2V bandgap reference built in that you can try first. E.g. look at:
https://forum.pjrc.com/threads/25532-ADC-library-update-now-with-support-for-Teensy-3-1

The 1.2V internal reference isn't great, but it should do better than the fluctuations you are getting.

A different reference won't solve the problem completely, since the Teensy analog VDDA will still fluctuate (tied to 3.3V via a ferrite). So if it doesn't work well enough, I would power the SD card with a separate power supply. E.g., there are SD card extension cables, where you could splice in power.

@j-protex
Copy link
Author

Thanks again for your answer. I removed the 470 Ohm resistor and used an external 3.3 V regulator for AREF.
Results seems to be perfect now. I couldn't see anything weird in the signal!
I already ordered a shunt reference to try that too. This can then be connected directly to AREF without removing the resistor before?

@j-protex
Copy link
Author

Hello again,

after using your logger for a lot of measurements I came across another problem:
I am now using it for logging 3 motion-sensor signals. The measurements always take a few seconds, depending on whether there is a motion detected. After logging, the Teensy goes back into sleep mode until it is woken up by a motion trigger again.
I want to use this system in the field, where it is supposed to measure for a few days. The first measurements are always fine, but then, after a certain time which I can not determine and I don't see when and why it happens, all the files have the maximum file size (log_file_size) and there is no content. I can't say that it happens after a certain amount of data is saved or that it depends on the number of files..
Any idea why this happens?

Best regards,
Julian

@tni
Copy link
Owner

tni commented Nov 4, 2018

I just saw your comment. No, I have no idea why the file would be empty. Everything is working fine in my tests. I've had issues with the SdFat library in the past, where it was unable to read some valid file systems. The library comes with an example for formatting the SD card. You might want to use that to start with a clean file system.

If you can reproduce the issue, please post an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants