Hi everybody! I am making a project, a touch button with a resistor and a capacitor connected to an ATmega168PA microcontroller. I do the calibration of the touch button once when starting the program. I want to make the calibration so that it works for the duration of the touch button (with some periodicity so that the calibration is done). Tell me how to do it? If, for example, the touch button becomes dirty or water gets on the touch button.
Post a simple sketch that shows this calibration process, and shows how the touch button is then used. Like make an LED follow the touching or whatever.
a7
Please post a schematic and explain the purpose of the calibration.
and explain the purpose of the calibration.
The sensor polling algorithm is as follows:
Initially, logic 0 is applied to pin D3. Thus, current flows from the power supply through the megohm resistor to the pin. If the sensor was charged, then the charge from it will also drain into pin D3.
At the time of the poll, we switch the pin from output to input (pullups are disabled!). At this moment, the pin goes into a high-impedance state, with a resistance of the order of several tens of MΩ. The current in the direction of the pin practically stops flowing, and begins to flow towards the sensor. As soon as the sensor is charged to the voltage level of logic 1, this input of the microcontroller will show one.
By measuring the time that has passed from the moment D3 was transferred to a high-impedance state until unity appears on it, we can conclude that the sensor capacitance has changed.
void CallibrateButton(unsigned char button_id, unsigned int open_button_time) {
// Calibration is carried out to estimate the charge time of the sensor without touching
// Since I'm using port B in my case, I need to make sure that it works as a Digital Out before starting the poll
// The state of port B in the PIC18F2580 depends, among other things, on the ADCON1 register
ADCON1 |= 0b00001000;
TRISB &= ~(1 << button_id); // Out port
LATB &= ~(1 << button_id); // To port zero
__delay_us(200); // Wait until the sensor is discharged
TMR0H = 0; TMR0L = 0; GIE = 0; TMR0ON = 1;
// Reset the timer, disable interrupts and start the timer
TRISB |= (1 << button_id); // Set port to high impedance state
while ( (PORTB&(1 << button_id)) == 0 ); // wait until the port goes one
TMR0ON = 0; GIE=1; // Turn off the timer and enable interrupts
open_button_time = TMR0 + 5;
// Save the value of the timer, with a margin to avoid false clicks
// Instead of "5" here you can use a variable and adjust the sensitivity with it
// In my case, I just used a 16-bit timer and a global variable of type int,
// But in general, an 8-bit timer should be enough
TRISB &= ~(1 << button_id); // Out port
LATB &= ~(1 << button_id); // To port zero
}
It's obvious that you cut and pasted that from a technical document. Instead, please provide links to all the relevant technical documentation that you are using.
Please explain the purpose of the calibration, in your own words. Please identify and provide information about the sensor.
Calibration is carried out to estimate the charge time of the sensor without touching
I can't find this article online.
Without information, I can't help you. It would be a waste of time. Good luck with your project.
@roman_arduino what @alto777 should have said is
Please post a complete it compiles and runs sketch that shows the calibration process and also demonstrates the use of the calibrated touch input.
Don't rush on my account. I have to work in my taxes now. But anybody reading this will probably benefit from you doing, so.
a7
Okay, I just wanted to know how the calibration works. Maybe you just have ideas.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.