Uživatel:Abbeahme

Z MAM wiki

Přejít na: navigace, hledání

Semestral work.


                                     ' touch a sensor'

This is a simple circuit which can detect when you touch a sensor connected to one of the sensor inputs. It can be used to add a touch switch to your computer for example. It uses an AVR micro controller, the AT90S2313. This is overkill. I can add a lot more sensors than the two sensors I have now, but I had a 2313 to spare and I didn't need more than two sensor :). Anyway, the basic idea is really simple. Make one pin output and another input. Connect a resistor between these pins. The resistor together with the human capacitance (about 100 pF) forms an RC network. The AVR set the output to low and then make a transition from 0V to +5 V. 5 µs after this switch, the logic level at the input pin is sampled. If someone is touching the probe connected to the input pin, the capacitor (=human) will not be fully charged, and the input will be a digital 0 and vice versa. Soubor:1000.jpg Schematic and board layout


This is the schematic. The potentiometers are there to adjust the sensitivity. 0.5 MOhm is usually a good value.


Soubor:2000.jpg


This is the board layout (made in EAGLE)

Soubor:3000.png


Listing:

  1. include <avr/io.h>
  1. include "spin_delay.h"


unsigned int samplecount;

unsigned int samplevalues;

unsigned int temp;

void sensor1(void){

samplecount = 0;

samplevalues = 0;

for(int i=0;i<8;i++){

PORTB &= ~(1 << 0);

ms_spin(2);

PORTB |= (1<<0);

us_spin(5);

temp = PINB;

       if (!(temp & (1<<1)))
               samplevalues++;

}

if (samplevalues>=4)

       PORTD |= (1 << 0);

else

       PORTD &= ~(1 << 0);

}

void sensor2(void){

samplecount = 0;

samplevalues = 0;


for(int i=0;i<8;i++){

PORTB &= ~(1 << 2);

ms_spin(2);

PORTB |= (1<<2);

us_spin(5);

temp = PINB;


       if (!(temp & (1<<3)))
               samplevalues++;

}



if (samplevalues>=4)

       PORTD |= (1 << 1);

else

       PORTD &= ~(1 << 1);


}

int main (void){


DDRB = 0b00000101;

DDRD = 0xFF;

PORTB = 0x00;

PORTD = 0x00;


while(1){

       sensor1();
       sensor2(); 
       }

}

Osobní nástroje