Accessing Both 16 bit timers on the 32U4

Hi, I am currently building a sensor that uses capacitance to meter the level of various liquids and I am a little stuck at the moment.

I have built a sensor and a prototype that work well but I am having an issue with the leads to the sensor, any soft of interference drastically affects the readings. My idea was to use a system similar to kelvin leads. However I need to use a 16 bit timer for each capacitance measurement and the 328P only has one. Now the 32U4 does have two but with the library I am using https://www.pjrc.com/teensy/td_libs_FreqMeasure.html to measure the frequency produced by the sensors. I have no Idea how to access the second 16 bit timer. Any help is gratefully appreciated.

Original Idea:

Kelvin Lead Idea:

pguerra75: Hi, I am currently building a sensor that uses capacitance to meter the level of various liquids and I am a little stuck at the moment.

I have built a sensor and a prototype that work well but I am having an issue with the leads to the sensor, any soft of interference drastically affects the readings. My idea was to use a system similar to kelvin leads. However I need to use a 16 bit timer for each capacitance measurement and the 328P only has one. Now the 32U4 does have two but with the library I am using https://www.pjrc.com/teensy/td_libs_FreqMeasure.html to measure the frequency produced by the sensors. I have no Idea how to access the second 16 bit timer. Any help is gratefully appreciated.

Original Idea:

Kelvin Lead Idea:

You can access the timer directly at low level. You will need to explain exactly how the system works and how the liquid level relates with the reading a counter can perform.

With that should be quite straightforward to visualize a way to correctly set the timer.

Casemod,

  1. The sensor is a set of wound wires that change in capacitance based on the amount of liquid they are submerged in.
  2. The capacitance is then converted to a frequency using a 555 timer circuit.(http://cpu86.hackhut.com/2011/03/01/555-contest-entry-capacitance-meter/)
  3. That frequency is then read using a 16 bit timer on the arduino at which point I can do the math on the leads + sensor and then just the "kelvin" leads. Once I know the capacitance of both and can correct for interference by subtracting the kelvin lead value form the leads+sensor value.
  4. After that it is the simple matter of calculating level based on know dielectric values of the liquid in which it is submerged.

My issue is one of experience, I am not well experienced in access these timers without the help of libraries, I have looked over the library I am using to access the one timer and although I do understand a good portion of it I cant seem to figure out how I would modify it to further access the second timer.

Paul

pguerra75: Casemod,

  1. The sensor is a set of wound wires that change in capacitance based on the amount of liquid they are submerged in.
  2. The capacitance is then converted to a frequency using a 555 timer circuit.(http://cpu86.hackhut.com/2011/03/01/555-contest-entry-capacitance-meter/)
  3. That frequency is then read using a 16 bit timer on the arduino at which point I can do the math on the leads + sensor and then just the "kelvin" leads. Once I know the capacitance of both and can correct for interference by subtracting the kelvin lead value form the leads+sensor value.
  4. After that it is the simple matter of calculating level based on know dielectric values of the liquid in which it is submerged.

My issue is one of experience, I am not well experienced in access these timers without the help of libraries, I have looked over the library I am using to access the one timer and although I do understand a good portion of it I cant seem to figure out how I would modify it to further access the second timer.

Paul

its not at all that hard to set up the timers.

Timer 0 is used by the system, so you can use timer 1 or two in normal arduinos. I am not familiar with the 32u4, so you have two check. Most important is if you need other functions like PWM to check that you are not using the respective timers.

The real problem when using libraries is that timer registers do change and therefore you are likelly to get stuck since the registers on atmega 328 may not be the same as on atmega 32u4. Using low level makes it very easy to port them. I, for example change between atmega 8, 328 and 644 and with a library i would be stuck with a platform.

Now back to the original problem,

If you are doing level measurement it is advisable to just do it in a given period rather than continuously. This is to avoid galvanic corrosion to the terminals (and liquid contamination).

What is the range of frequencies you expect to measure and why are you having issues with your current implementation right now? Why exactly do you need a 16bit timer rather than using a 8bit with a prescaller?

Casemod,

Again, thanks for the reply. I am not at home right now so I will have to get back to you on the actual values I am looking at.
Ballpark figures though are about 10pf per sensing inch when in air and 11.5pf per sensing inch when in liquid. Galvinc corrosion isn’t really an issue as the sensor leads are insulated in Teflon. I would like to use 16 bit timers for reasons of resolution, and the kelvin leads portion if I can make work will only be in the 4-5 pf capacitance range which means it will require very accurate frequency measurements.

Of course the frequencies can be adjusted with larger resistor values to make it more accurate with an 8 bit timer, but larger resistor values mean large drifts from temperature.

Again thanks and I will get back to you with more info when I get off of work.

Paul

Well, do let us know then.

Resolution wise you can let the timer overflow and count the amount of overflows. Basically you have a 16bit timer made in software with no loss of functionality, just a bit of CPU overheard.

I just had the hard task of implementing a 32bit timer with the arduino using a 16bit timer, so you might be able to re-use some of my code. It may even be more simple, if the sensors work on a particular frequency.

But lets wait for those specs before pondering any particular solution.