Showing posts with label event chaning. Show all posts
Showing posts with label event chaning. Show all posts

Monday, January 5, 2015

Inductive Proximity Sensor

Inductive proximity sensors are typically used to detect the presence or absence of a metal target and the output often emulates a switch. We can meet it in almost every area of factory automation, transport, home automation. Every place where necessary to know when moving part to stop. They use a high-frequency electromagnetic AC field that interacts with the target. We may say it's a kind of low-range metal detector.

flat printed coil
This example uses flat printed coil as a sensing inductor, that noticeably simplified hardware part. This coil easy can  be drawn in minute by scripts in Eagle. However, it can surely sense metal objects in distance 0.1" (2-3mm) or even aluminum foil, so we can track non-metal surface also, just stick a square inch of foil . No additional magnet-conductive core needed, for quick attempt works even hand-winded coil with ten turns of any wire on 1" diameter base.


Schematic twice more complicated. then previous sensor, but two diodes and two resistors with one capacitance not a big issue, isn't it? Like in previous one,  all started by master timer, however here impulse starts faded RF sin wave (~10MHz) on coil by L1C1 chain. If metal target close enough, sin wave fades more, because target act as short-circuited secondary coil. Next this RF impulse comes through second diode, and performs detection of envelope curve on ADC internal RC chain (8pF 50kΩ). Now we have to measure this DC "hill" just in time it comes, and event chaining help us again.

Code example almost the same, just a few differences. In main cycle -  proportion replaced by simple  on/off switch with hysteresis. And off cause, another constants, and another ADC timing.  Output (pin3) high(1) when coil closed by metal target, low(0) when open.

Event chart and other software details remains the same:
code compiled in Keil µVision 4 .71 with standard libraries for STM32F0.

UPD:
Recently discover new variant of schematic - v2 works better.
Charts almost the same, except direct leaking TIM pulse front through diodes.
However, this circumstance don't disturb us, because ADC turns on little later.


Monday, December 15, 2014

Is there some RTOS?

Code example for capacitive level sensor seems short and simple (there is even haven't used interrupts!), but some parts may looks quite unusual.

First, seems like there is no RTOS. Yes, there no side RTOS, just hardware drivers. However, if look closer, we realize that main cycle plays the same role  like a main cycle in any RTOS, clocked by hardware timer.

event chart, hardware-driven RTOS

Difference in who clocks CPU - actually there TIM2 triggers ADC,  then ADC starts measurements, and only when it done, ADC triggers main cycle. All CPU needs to do is get fresh data, and work with it. We may say there is a very small hardware-driven RTOS. Or, as was mention before, there is not a emulation of hardware device by CPU, but chains of peripheral devices, configured and serviced by CPU.

This brings us to another difference - event chaining procedures. This procedures connect hardware in functional chains, it allow to work together without disturbing CPU. Actually, in this example peripherals drives CPU, and CPU just services peripherals. All other time CPU free to think or sleep. First may be used for filtering or statistic, second - to lowing current consumption.

Because of simplifying code example, there are simple pooling loop in ADC cycle, and it's means that current consumption close to maximum 14mA. But consumption can be significantly lowered close to zero by using sleep mode with interrupt routine. By the way - event chaining appear not to replace interrupts, but to complement it from hardware side, for unloading CPU from extrinsic tasks.

Code compiled in Keil µVision 4 .71 with standard libraries for STM32F0.

Final binary code not exceed 7kb in size, and leaves free 6kb even for cheapest chip in line like STM32F050F4P6.


Saturday, December 13, 2014

Too much impulses

Usually, low capacitance measured by sending high frequency (from hundred kHz to tens MHz) impulses through it, and look at attenuation. But for capacitance there is enough just one pulse. We can lowed quantity of impulses for million times,  spend much less energy, and reduce radio interference. So, let's dispense just one pulse. And it radically simplified hardware part:


Yes, just diode and resistor! Who can imagine something more simple? But simplicity in hardware needs kind of tricky (but not complicated) software. First, we send short pulse from timer output, charge sensor, and measure how voltage drops in discharge on resistor. This trick possible only with perfect synchronization between timer and ADC. And event chaining help us.

Timer pulse needs right width. If it will be too short, pulse can't charge sensor high enough, but if pulse too long, ADC will  measure top of pulse itself, instead of voltage falls curve on capacitance. Ideally, pulse width need to correspond with ADC "switch on" delay, it about 0.2μs.

In that case all we need is read ADC data reg, because all other work will be performed inside Cortex ADC (a couple of sampling shots and approximation). Actually, we measure not a point, but  slope area between start and stop of ADC sampling time (green stripes on pic). And this slope pretty close to linear dependence of  capacitance.

Friday, December 12, 2014

Just measure this, thats all.

Easy to say, but there are question of measuring real low capacitances. For instance, for tubes:

length (l)=120millimeter =0.12meter
outer conductor diameter (b)=28millimeter =0.028meter
inner conductor diameter (a)=19millimeter =0.019meter

This wonderful cylindrical capacitor calculator shows only 17pF for dry one!

Conversions: 
permittivity (ε)=8.85picofarad/meter =8.85E-12farad/meter (air)
capacitance (C)=17.20 picofarad

But inside every Cortex chip ( for instance: STM32F050F4P6) there are a powerful ADC, with near 1μs sample time, 7pF input capacitance, and 12bit resolution. And it can be synchronized with other peripheral (e.g. timers) by dedicated hardware link, configured with other peripheral registers. This feature called event chaining.

Let's calculate time constant for dry sensor with 91kΩ resistor (assume this enough for low interference) RC Time Constant Calculator says 1.547μs for 17pF 91kΩ. Seems like ADC can catch it! Notice, we need to sample fist half of curve, because this part less nonlinear.

All this give us a hope, that for this task we don't need any additional active components like FET or op-amp. Just  resistor and diode!


Wednesday, December 10, 2014

Event-chaining in peripheral

Here will be placed examples of some devices uses Cortex M0 microcontroller. This low-consumptive 32-bit core MC's fast enough, had impressive peripheral, and easily programmed by high level language (C++). Here also enough space for data logging and statistic.

But main benefit is new type of connection for peripheral, that allows event-chaining between inner peripheral devices as timers, ADCs, memory. It gives simple and sure synchronization between devices by excluding software delays. Reduces using central processor (CPU) , it lowing current consumption and keeps CPU free for math and control. This is simple and quick way to create real-time low-consumptive devices with high reliability. Moreover, seems like there is a great milestone from emulation electronic device by CPU, like it was before,  to fully CPU-independent (except clocking) real-time electronic device inside chip, just configured and serviced by CPU.