Autor Tema: Explicacion INT_AD y Touch Capacitivo por favor....  (Leído 21811 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado planeta9999

  • Moderadores
  • DsPIC30
  • *****
  • Mensajes: 3520
    • Pinballsp
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #30 en: 05 de Julio de 2013, 19:33:09 »
Gracias, excelente aporte...

Y en caso de estos botones, como es la conexión ?, ya que veo que es una rejilla...



Los conecto en matriz, pero esta configuración solo es necesaria si tienes muchos botones, en mi caso tengo un diseño con 22 botones. Para diseños con pocos botones, los diseñas sólidos y cada botón a una patilla.






Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7912
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #31 en: 05 de Julio de 2013, 19:47:54 »
Si uso botones comunes (si multiplexar), los hago sólidos y con rodeo de masa alrededor??
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7912
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #32 en: 05 de Julio de 2013, 20:09:42 »
Aquí pongo el código que tengo a medio funcionar, ya que según comente creo que mis botones no son los mejores, je..je..

El archivo .h

Código: C
  1. /#include <18F26K80.h>
  2. //#device adc=10
  3.  
  4. #FUSES NOWDT                    //No Watch Dog Timer
  5. //#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
  6. //#FUSES SOSC_DIG                 //Digital mode, I/O port functionality of RC0 and RC1
  7. #FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
  8. #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
  9. //#FUSES PLLEN                    //PLL habilitado
  10. #FUSES PUT                      //Power Up Timer
  11. #FUSES NOBROWNOUT               //No brownout reset
  12. //#FUSES WDT_NOSLEEP              //Watch Dog Timer, disabled during SLEEP
  13.  
  14. #use delay(int=8000000)//, RESTART_WDT)
  15.  
  16. #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)//,RESTART_WDT)
  17.  
  18. //#USE TOUCHPAD(RANGE=H, THRESHOLD=6, SCANTIME=32, SOURCETIME=10, PIN_A0='A', PIN_A1='B', PIN_A2='C')
  19. #USE TOUCHPAD(RANGE=M, THRESHOLD=4, SCANTIME=40, SOURCETIME=10, PIN_A0='A', PIN_A1='B', PIN_A2='C')
  20. // aqui entrar a Tools > Device Editor > elegir el Pic > (Cuadro central)Other Features > Cap Sens Mode y elegir cual es el formato utilizado si no esta.

Y el archivo .c

Código: C
  1. #include <Uso CTMU Touch.h>
  2. //#use fast_io(A)
  3. #ZERO_RAM
  4. #Define Led_Amar Pin_C4
  5.  
  6. void main()
  7. {
  8.    char c = 'D';
  9.    int16 Conteo;
  10.   // set_tris_a(0b00000111);//RA2 input
  11.    delay_ms(5000); //pausa para levantar el port USB
  12.    
  13.  //  setup_adc_ports(ALL_ANALOG);
  14.  //sets all the adc pins to analog
  15.  
  16.    enable_interrupts(GLOBAL);
  17.  
  18.    TOUCHPAD_STATE(1);     //calibrates, then enters normal state
  19.  
  20.       printf(" MTOUCH con CTMU...\n\r");
  21.      
  22.    while(TRUE)
  23.    {
  24.       //TODO: User Code
  25.      if ( TOUCHPAD_HIT() )
  26.       {
  27.          c = TOUCHPAD_GETC();   //will wait until a pin is detected
  28.          Conteo = 0;
  29.       }
  30.      
  31.       switch (c)
  32.       {
  33.  
  34.           case 'A':
  35.           case 'B':
  36.           case 'C':     output_high(Led_Amar);
  37.                         delay_ms(50);
  38.                         output_low(Led_Amar);
  39.                   break;
  40.      
  41.           default:      c = 'D';
  42.      
  43.                   break;
  44.        }
  45.      
  46.       printf("Tecla pulsada: %c ...\r",c);
  47.            
  48.    }
  49.  
  50. }

como veran, en el codigo estan los rastros de mis diversas pruebas, je..je..

Y una foto de mi "teclado", cuidado que tiene derechos de Copyrigth !!!   :D :D :D :D

De frente:



Y por detrás, el secreto!!! :D :D

Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado planeta9999

  • Moderadores
  • DsPIC30
  • *****
  • Mensajes: 3520
    • Pinballsp
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #33 en: 06 de Julio de 2013, 08:39:10 »

Si uso botones comunes (si multiplexar), los hago sólidos y con rodeo de masa alrededor??


Si, así están hechos en las placas demo de Microchip, como estas, no tienen plano de tierra bajo el botón, pero si entre botones.






« Última modificación: 06 de Julio de 2013, 08:43:09 por planeta9999 »

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7912
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #34 en: 06 de Julio de 2013, 09:09:18 »
O sea que en mi "diseño" solo me falto el plano de masa entre los botones !!! :D :D :D
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #35 en: 28 de Julio de 2013, 18:21:23 »
hey there

just to show what I'm working so far, is the second version of my CANBus Board, but with a enhance CAN with the PIC18F26K80, and Touch Sensors added.

Still working on the Touch Library


"Hola

sólo para mostrar lo que estoy trabajando hasta el momento, es la segunda versión de mi Junta CANBus, pero con una mejorar CAN con el PIC18F26K80, añadió y Sensores táctiles.

Sigo trabajando en la Biblioteca Touch"






« Última modificación: 29 de Julio de 2013, 00:14:21 por rotting79 »
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7912
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #36 en: 28 de Julio de 2013, 23:08:57 »
Con que compilador programas rotting79 ??

Para los moderadores: No se que pasa pero veo un segundo las imagenes y videos y luego ya no se ven mas...
alguna idea de porque ocurre esto ??
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #37 en: 29 de Julio de 2013, 00:18:37 »
With that compiler rotting79 programs?

To the moderators: No passing but I see one seconds pictures and videos and then are no longer more ...
any idea why this happens?

I use XC8 as my main compiler

...I don't know what you mean with "are no longer more" maybe a bug, but please visit the youtube page to see what's going on the video

Yo uso XC8 como mi compilador principal

... no sé lo que quieres decir con "no son más" tal vez un error, pero por favor, visite la página de youtube para ver lo que está pasando en el video
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #38 en: 29 de Julio de 2013, 01:03:36 »
Yo he visto bien el vídeo, Marcos, ¿lo ves bien ya o será algo de tu pc?

Desconectado stk500

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 4919
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #39 en: 29 de Julio de 2013, 03:44:58 »
yo veo el video perfecto!

I see it very well.

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #40 en: 10 de Agosto de 2013, 17:41:09 »
there again!!

This is the second video about the CAN Bus board V2,  with PIC18F26K80, on this, I'm testing the Touch Sensor Library that I made.

In the first channel there are two simple Touch Sensors Buttons, debugged at 0:41, (*.csv file), and in the channel two there is a Slide Touch Sensor, debugged at 0:49, to see the value from the Slid, which is a unsigned int (16 bit) I moved to the ECCP, to the PWM register, and you can see the dimmer action over the LED, adn the oscilloscope at 1:08.

At the very end, you can see the two sensors'value and the result of it at 1:31



Este es el segundo video sobre el CAN Bus tablero V2, con PIC18F26K80, en esto, estoy probando la Biblioteca del sensor táctil que hice.

En el primer canal hay dos sensores táctiles simples botones, depuradas en doce y cuarenta y uno, (*. Csv) y en el canal dos hay un Sensor Touch Slide, depurado a doce y cuarenta y nueve minutos, para ver el valor de la Slid , que es un entero sin signo (16 bits), me trasladé a la PECC, en el registro PWM, y se puede ver la acción más tenue sobre el LED, adn el osciloscopio a las 1:08.

Al final, se puede ver los dos sensors'value y el resultado de la misma a las 1:31


A quick question: how can I share my library?, I've seen those "windows"  where u share your code and can scroll it
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7912
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #41 en: 10 de Agosto de 2013, 18:58:23 »


« Última modificación: 10 de Agosto de 2013, 19:11:01 por MGLSOFT »
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #42 en: 10 de Agosto de 2013, 20:54:28 »
here is the library:

aquí está la biblioteca with XC8 Compiler:

CTMU.C


Código: C
  1. /************ CTMU.c *********/
  2.  
  3. #include "CTMU.h"
  4. #include "stdio.h"
  5.  
  6.  
  7.  
  8. /** struct where the values for every touch sensor saves its own values **/
  9. typedef struct _TOUCH_SENSOR
  10. {
  11.         unsigned int            Threshold;              // Un-pressed Sensor value.
  12.         unsigned char   Trip;                   // Difference between pressed and un-pressed switch.
  13.         unsigned char   Hysteresis;             // Amount to change.
  14.         unsigned char   SensorState;    // Actual Sensor State.
  15.         unsigned int            SensorRead;             // ADC value.
  16.         } TOUCH_SENSOR;
  17.  
  18. volatile TOUCH_SENSOR sensors [ NUMBER_OF_TOUCH_SENSORS ];
  19.  
  20. /*******************************************************************/
  21. /*      -SetUpCTMU ( Edges Configurtion, Current Source,
  22.                                 Edge 2 Polarity, Edge 1 Polarity,
  23.                                 Current Source Range )
  24. /*              -Edges Configurtion
  25. /*              -Current Source
  26. /*              -Edge 2 Polarity
  27. /*              -Edge 1 Polarity
  28. /*              -Current Source Range
  29. /*              *configures the CTMU Port.
  30. /*
  31. /*      -SetUpTouchSensor ( TouchSensorNumber, Threshold
  32. /*                                              Trip, Hysteresis,
  33. /*                                              ChargeDelay, DischargeDelay )
  34. /*              -TouchSensorNumber
  35. /*              -Threshold
  36. /*              -Trip
  37. /*              -Hysteresis
  38. /*              -ChargeDelay
  39. /*              -DischargeDelay
  40. /*              *sets the Touch Sensor Channel to be read.
  41. /*
  42. /*      -DecodeTouchSensor ( TouchSensorNumber )
  43. /*              -TouchSensorNumber
  44. /*              *Returns the value stored in ptrSensor -> SensorState
  45. /*               if pressed = 1; else = 0.
  46. /*
  47. /*      -DebbugTouchSensor ( TouchSensorNumber, TouchSensorNumber )
  48. /*              -TouchSensorNumber
  49. /*              -TouchSensorNumber
  50. /*              *Prints out the value of any two touch sensors
  51. /*
  52. /*      -SliderTouchSensor ( TouchSensorNumber0,  TouchSensorNumber1)
  53. /*              -TouchSensorNumber0
  54. /*              -TouchSensorNumber1
  55. /*              *Returns the unsigned int value ( 16bit) of the Slider Sensor.
  56. /*              *Require two sensors.
  57. /******************************************************************/
  58.  
  59. /********* Configures the CTMU Module Register ********************/
  60. void SetUpCTMU ( unsigned char CTMUConfig0, unsigned char CTMUConfig1,
  61.                                 unsigned char CTMUConfig2, unsigned char CTMUConfig3,
  62.                                 unsigned char CTMUConfig4 )
  63. {
  64.         CTMUCONH = 0x00;                                                        // Set to POR/BOR values.
  65.         CTMUCONL = 0x00;
  66.         CTMUICON = 0x00;       
  67.  
  68.         CTMUCONHbits . EDGEN = CTMUConfig0;     // Edges are blocked.  
  69.         CTMUCONHbits . IDISSEN = CTMUConfig1;   // Analog current source output is not grounded.
  70.                
  71.         CTMUCONLbits . EDG2POL = CTMUConfig2;   // Edge 2 is programmed for a positive edge response.
  72.         CTMUCONLbits . EDG1POL = CTMUConfig3;   // Edge 1 is programmed for a positive edge response.
  73.  
  74.         CTMUICONbits . IRNG = CTMUConfig4;              // Current Source Range Select.
  75.  
  76.         CTMUCONHbits . CTMUEN = ENABLE;         //Enable the CTMU.
  77.         }      
  78.  
  79. /********* Configure the Touch Sensor to use ********************/
  80. void SetUpTouchSensor ( unsigned char TouchSensorNumber, unsigned int Threshold,
  81.                                                 unsigned char Trip, unsigned char Hysteresis,
  82.                                                 unsigned char ChargeDelay, unsigned char DischargeDelay )
  83. {
  84.         TOUCH_SENSOR* ptrSensor;
  85.         ptrSensor = ( TOUCH_SENSOR* ) sensors + TouchSensorNumber;      // Pointing to the Touch Sensor
  86.                                                                                                                                         // to be Set it.
  87.         ptrSensor -> Threshold = Threshold;                                                             // Pasing the values to
  88.         ptrSensor -> Trip = Trip;                                                                                       // the Sensors
  89.         ptrSensor -> Hysteresis = Hysteresis;
  90.         }      
  91.  
  92. /********* Decode the Touch Sensor Selsected; verified if it is Pressed or not ********************/
  93. int DecodeTouchSensor ( unsigned char TouchSensorNumber )
  94. {
  95.         TOUCH_SENSOR* ptrSensor;
  96.         ptrSensor = ( TOUCH_SENSOR* ) sensors + TouchSensorNumber;      // Pointing to the Touch Sensor
  97.                                                                                                                                         // to be Decode it.
  98.         CTMUCONL = CTMUCONL & 0xFC;                                                             // 0xFC = 0b11111100.
  99.  
  100.         ADCON0 &= 0b10000011;                                                                                   // Cleaning up the previous channel.
  101.         ADCON0 |= TouchSensorNumber << 0x02;                                                    // Setting the AD channel to read
  102.                                                                                                                                         // without changing the ADCON0 value.
  103.  
  104.         CTMUCONHbits . IDISSEN = START;                                                 // Drain charge on the circuit.
  105.         __delay_us ( DEFAULT_DISCHARGE_TIME );
  106.         CTMUCONHbits . IDISSEN = STOP;                                                          // End drain of circuit.
  107.         CTMUCONLbits . EDG1STAT = START;                                                        // Begin charging the circuit
  108.                                                                                                                                         // using CTMU current source.
  109.         __delay_us ( DEFAULT_CHARGE_TIME );
  110.         CTMUCONLbits . EDG1STAT = STOP;                                                         // Stop charging circuit.
  111.  
  112.         ADCON0bits . GO = 0x01;                                                                         // Starts the reading of the capacitive sensor.                        
  113.         while ( ADCON0bits . GO );                                                                              // Wait until convertion is done.
  114.  
  115.         ptrSensor -> SensorRead = ( ( ( unsigned int ) ADRESH ) << 8 ) |        
  116.                         ( ADRESL );                                                                                             // Return the value from two Bytes.
  117.  
  118.         CTMUCONHbits . IDISSEN = START;                                                 // Drain charge on the circuit.
  119.        
  120.         if ( ptrSensor -> SensorRead < DEFAULT_THRESHOLD - DEFAULT_TRIP )
  121.         {
  122.                 ptrSensor -> SensorState = PRESSED;
  123.                 }      
  124.  
  125.         else if ( ptrSensor -> SensorRead > DEFAULT_THRESHOLD - DEFAULT_TRIP + \
  126.                         DEFAULT_HYST )
  127.         {
  128.                 ptrSensor -> SensorState = UNPRESSED;
  129.                 }      
  130.  
  131.         return ptrSensor -> SensorState;
  132.         }
  133.  
  134. /********* Debug the touch Sensor; debug propouse ********************/
  135. void DebbugTouchSensor ( unsigned char TouchSensorNumber0, unsigned char TouchSensorNumber1 )
  136. {
  137.         TOUCH_SENSOR* ptrSensor0;
  138.         ptrSensor0 = ( TOUCH_SENSOR* ) sensors + TouchSensorNumber0;            // Pointing to the Touch Sensor
  139.                                                                                                                                                         // to be Decode it.
  140.         TOUCH_SENSOR* ptrSensor1;
  141.         ptrSensor1 = ( TOUCH_SENSOR* ) sensors + TouchSensorNumber1;                    // Pointing to the Touch Sensor
  142.                                                                                                                                                         // to be Decode it.
  143.  
  144.         printf ( " \n%d,%d", ptrSensor0 -> SensorRead   , ptrSensor1 -> SensorRead );   // Printing out the actual value
  145.                                                                                                                                                         // on the sensor selected.
  146.         }
  147.        
  148. /********* Return the Slider Value Selected ********************/
  149. unsigned int CurrentSliderVal;
  150.  
  151. int SliderTouchSensor ( unsigned char SlideSensorNumber0, unsigned char SlideSensorNumber1 )
  152. {
  153.         unsigned int SliderTouchSensorValue, SliderTempVal;
  154.         unsigned char Sensor0, Sensor1;
  155.        
  156.         Sensor0 = DecodeTouchSensor ( SlideSensorNumber0 );
  157.         Sensor1 = DecodeTouchSensor ( SlideSensorNumber1 );
  158.  
  159.         TOUCH_SENSOR* ptrSlideSensor0;
  160.         ptrSlideSensor0 = ( TOUCH_SENSOR* ) sensors + SlideSensorNumber0;       // Pointing to the Touch Sensor
  161.                                                                                                                                                         // to be Read.
  162.         TOUCH_SENSOR* ptrSlideSensor1;
  163.         ptrSlideSensor1 = ( TOUCH_SENSOR* ) sensors + SlideSensorNumber1;               // Pointing to the Touch Sensor
  164.                                                                                                                                                         // to be Read.
  165.         SliderTouchSensorValue = CurrentSliderVal;
  166.  
  167.         if ( ( Sensor0 ) || ( Sensor1 ) )
  168.         {
  169.                 SliderTempVal = ( ptrSlideSensor0 -> SensorRead * 3 ) - ( ptrSlideSensor1 -> SensorRead );
  170.        
  171.                 SliderTouchSensorValue = SliderTempVal / FACTOR_10BIT_RESOLUTION
  172.                                                                 - DIFFERENTIAL;
  173.                 CurrentSliderVal = SliderTempVal / FACTOR_10BIT_RESOLUTION
  174.                                                         - DIFFERENTIAL;
  175.                 }      
  176.  
  177.         return ( SliderTouchSensorValue );
  178.         }


here is the CTMU.h

Código: C
  1. /************ CTMU.h *********/
  2.  
  3. /********* A/D Port Configuration Control bits ********/
  4. #define TOUCH_SENSOR_ZERO               0x00    // The same as ADC channels.
  5. #define TOUCH_SENSOR_ONE                        0x01
  6. #define TOUCH_SENSOR_TWO                        0x02
  7. #define TOUCH_SENSOR_THREE              0x03
  8. #define TOUCH_SENSOR_FOUR                       0x04
  9.  
  10. /********* Edge Enable bit ********/
  11. #define EDGE_NOT_BLOCKED                        0x01
  12. #define EDGE_BLOCKED                            0x00
  13.  
  14. /********* Edge Sequence Enable ********/
  15. #define CURRENT_GROUNDED                        0x01
  16. #define CURRENT_NOT_GROUNDED    0x00
  17.  
  18. /********* Edge 2 Polarity Select bit ********/
  19. #define EDGE_2_POSITIVE                         0x01
  20. #define EDGE_2_NEGATIVE                 0x00
  21.  
  22. /********* Edge 1 Polarity Select bit ********/
  23. #define EDGE_1_POSITIVE                         0x01
  24. #define EDGE_1_NEGATIVE                         0x00
  25.  
  26. /********* Current Source Range Select bits ********/
  27. #define BASE_CURRENT_100                        0x03
  28. #define BASE_CURRENT_10                         0x02
  29. #define BASE_CURRENT_550nA                      0x01
  30. #define CURRENT_DISABLED                        0x00
  31.  
  32.  
  33. /********* Values to Set The Touch Sensors ********/
  34. #define DEFAULT_THRESHOLD                       2500    // Un-pressed switch value.
  35. #define DEFAULT_TRIP                                    100             // Difference between pressed and un-pressed switch.
  36.                                                                                                
  37. #define DEFAULT_HYST                            65              // Amount to change from pressed to un-pressed.
  38.                                                                                                  
  39. #define DEFAULT_CHARGE_TIME             2               // Time to charge and discharge.
  40. #define DEFAULT_DISCHARGE_TIME  35              // Time to discharge and discharge.
  41.  
  42.  
  43. /********* General Registers ********/
  44. #define ENABLE                                          0x01
  45. #define DISABLE                                         0x00
  46.        
  47. #define START                                                   0x01
  48. #define STOP                                                    0x00
  49.  
  50. #define PRESSED                                                 0x01    // Decoding the Touch Semsors.
  51. #define UNPRESSED                                       0x00
  52.  
  53.  
  54. /********* General Registers for Slider Tocuh Sensor ********/
  55. #define FACTOR_10BIT_RESOLUTION 0x05    // Factors for the Slider
  56. #define DIFFERENTIAL                                    0x12C  
  57.  
  58.  
  59. /********* Number of Sensors to be read in the uC ********/
  60. #define NUMBER_OF_TOUCH_SENSORS 0x05    // Number of Sensors to be read in the uC.
« Última modificación: 27 de Agosto de 2013, 23:48:11 por rotting79 »
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #43 en: 10 de Agosto de 2013, 20:58:01 »
here is one example how get the sensor as a button with PIC18F26K80


aquí es un ejemplo de cómo sacar el sensor como un botón con PIC18F26K80

Main.c file
Código: C
  1. #include        <xc.h>
  2.  
  3. #define _XTAL_FREQ      FREQ_16MHz
  4.  
  5. #include "SetUp.c"
  6.  
  7. bit Button0, Button1;
  8.  
  9. void main ( void )       //@0x100
  10. {
  11.         SetUp ( );
  12.  
  13.         SetUpCTMU ( EDGE_BLOCKED, CURRENT_NOT_GROUNDED,
  14.                                 EDGE_2_POSITIVE, EDGE_1_POSITIVE,
  15.                                 BASE_CURRENT_100 );
  16.        
  17.         SetUpTouchSensor ( TOUCH_SENSOR_ONE, DEFAULT_THRESHOLD,
  18.                                                 DEFAULT_TRIP, DEFAULT_HYST, DEFAULT_CHARGE_TIME,
  19.                                                 DEFAULT_DISCHARGE_TIME );
  20.  
  21.         SetUpTouchSensor ( TOUCH_SENSOR_TWO, DEFAULT_THRESHOLD,
  22.                                                 DEFAULT_TRIP, DEFAULT_HYST, DEFAULT_CHARGE_TIME,
  23.                                                 DEFAULT_DISCHARGE_TIME );
  24.  
  25.         printf ( " \n\f Sensor1, Sensor2... " );
  26.        
  27.         while ( TRUE )
  28.         {
  29.                 Button0 = DecodeTouchSensor ( TOUCH_SENSOR_ONE );
  30.                 Button1 = DecodeTouchSensor ( TOUCH_SENSOR_TWO );
  31.                
  32.                 if ( !PORTBbits . RB7 )                                 // For debbuging propouses.
  33.                         DebbugTouchSensor (     TOUCH_SENSOR_ONE, TOUCH_SENSOR_TWO      );
  34.  
  35.                 LED1_OFF;
  36.                 LED2_OFF;
  37.  
  38.                 if ( Button0 )
  39.                 {
  40.                         LED1_ON;
  41.                         }      
  42.                 if ( Button1 )
  43.                 {
  44.                         LED2_ON;
  45.                         }
  46.                 }              
  47.         }


and here is the SetUp.c file

Código: C
  1. /* CONFIG1L ************************/
  2. #pragma config  XINST = OFF                     // Extended Instruction Set.
  3. #pragma config  SOSCSEL = DIG                   // SOSC Power Selection and Mode Configuration.
  4. #pragma config  INTOSCSEL = HIGH        // LF-INTOSC Low-power.
  5. #pragma config  RETEN = OFF                     // VREG Sleep.
  6.  
  7. /* CONFIG1H ************************/
  8. #pragma config  IESO = OFF                              // Internal/External Oscillator Switchover.
  9. #pragma config  FCMEN = OFF                     // Fail-Safe Clock Monitor.
  10. #pragma config  PLLCFG = OFF                    // 4X PLL.
  11. #pragma config  FOSC = INTIO2                   // Oscillator.
  12.  
  13. /* CONFIG2L ************************/
  14. #pragma config  BORPWR = ZPBORMV        // BORMV Power-Level.
  15. #pragma config  BORV = 0x03                     // Brown-out Reset Voltage.
  16. #pragma config  BOREN = SBORDIS         // Brown-out Reset Enable.
  17. #pragma config  PWRTEN = ON                     // Power-up Timer.
  18.  
  19. /* CONFIG2H ************************/
  20. #pragma config  WDTPS = 0x01                    // Watchdog Timer Postscale.
  21. #pragma config  WDTEN = OFF                     // Watchdog Timer Enable.
  22.  
  23. /* CONFIG3H ************************/
  24. #pragma config  MCLRE = ON                      // MCLR Pin Enable.
  25. #pragma config  MSSPMSK = MSK7          // MSSP V3 7-Bit Address Masking Mode.
  26. #pragma config  CANMX = PORTB           // ECAN MUX.
  27.  
  28. /* CONFIG4L ************************/
  29. #pragma config  BBSIZ = BB1K                    // Boot Block Size.
  30. #pragma config  STVREN = ON                     // Stack Full/Underflow Reset.
  31.  
  32. /* CONFIG5L ************************/
  33. #pragma config  CP3 = OFF                               // Code Protection.
  34. #pragma config  CP2 = OFF                               // Code Protection.
  35. #pragma config  CP1 = OFF                               // Code Protection.
  36. #pragma config  CP0 = OFF                               // Code Protection.
  37.  
  38. /* CONFIG5H ************************/
  39. #pragma config  CPD = OFF                               // Data EEPROM Code Protection.
  40. #pragma config  CPB = OFF                               // Boot Block Code Protection.
  41.  
  42. /* CONFIG6L ************************/
  43. #pragma config  WRT3 = OFF                              // Write Protection.
  44. #pragma config  WRT2 = OFF                              // Write Protection.
  45. #pragma config  WRT1 = OFF                                      // Write Protection.
  46. #pragma config  WRT0 = OFF                              // Write Protection.
  47.  
  48. /* CONFIG6H ************************/
  49. #pragma config  WRTD = OFF                              // Data EEPROM Write.
  50. #pragma config  WRTB = OFF                              // Boot Block Write Protection.
  51. #pragma config  WRTC = OFF                              // Configuration Register Write.
  52.  
  53. /* CONFIG7L ************************/
  54. #pragma config  EBTR3 = OFF                             // Table Read Protection.
  55. #pragma config  EBTR2 = OFF                             // Table Read Protection.
  56. #pragma config  EBTR1 = OFF                             // Table Read Protection.
  57. #pragma config  EBTR0 = OFF                             // Table Read Protection.
  58.  
  59. /* CONFIG7H ************************/
  60. #pragma config  EBTRB = OFF                             // Boot Block Table Read Protection.
  61.  
  62.  
  63. #if     defined ( _PIC18F26K80_H_ )
  64.         #define FREQ_64MHz      64000000
  65.         #define FREQ_16MHz      16000000
  66.         #define FREQ_8MHz       8000000
  67.         #define FREQ_4MHz       4000000
  68.         #define FREQ_1MHz               1000000
  69. #endif
  70.  
  71. #define TRUE            0x01
  72. #define FALSE           0x00
  73.  
  74. #include "Oscillator.c"
  75. #include "UART.c"
  76. #include "ADC.c"
  77. #include "CTMU.c"
  78. #include "PullUps.c"
  79. #include "stdio.h"
  80.  
  81.  
  82.  
  83. #define TRUE    0x01
  84. #define FALSE   0x00
  85.  
  86. #define LED1_ON         PORTCbits . RC2 = 0x01;
  87. #define LED2_ON         PORTCbits . RC3 = 0x01;
  88.  
  89. #define LED1_OFF                PORTCbits . RC2 = 0x00;
  90. #define LED2_OFF                PORTCbits . RC3 = 0x00;
  91.  
  92.  
  93. void SetUp ( void )
  94. {
  95.         SetUpOscillator ( OSC_16MHz );
  96.  
  97.         TRISC = 0x00;
  98.  
  99.         TRISB = 0x08;
  100.         EnablePullUps ( WPU7 );
  101.  
  102.         CANCON = 0;
  103.         CANSTAT = 0;
  104.         ECANCON = 0b10000000;
  105.  
  106.         SetUpUART ( BAUD_RATE_57600 );
  107.        
  108.         SetUpADC ( sAN1 | sAN2, RIGHT_JUSTIFIED, VDD_VSS, FOSC_32 );
  109.  
  110.         LED1_OFF;
  111.         LED2_OFF;
  112.         }
« Última modificación: 12 de Agosto de 2013, 22:23:53 por rotting79 »
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado stk500

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 4919
Re: Explicacion INT_AD y Touch Capacitivo por favor....
« Respuesta #44 en: 11 de Agosto de 2013, 05:04:24 »
Very nice, Fein work..