Showing posts with label injected mode ADC. Show all posts
Showing posts with label injected mode ADC. 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.