qtouch library

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been playing with this library.
But I have some problem that I do not yet understand. I want to include a printf to display the values of sensors. And this is the problem.

I use an example from the library: avr4g2_8qt_example.

Apparantly it works since I get a signal on the debug lines (actually port C1/C0).

Now I add the following routine to the code

#include "touch_api_atmega168.h"
#include 
#include 
#include 
#include 
#include 
#include "rs232-t.h"

//Define functions for rs232
//======================			
void ioinit(void);     							// initializes IO
static int uart_putchar(char c, FILE *stream);	// stream based i/o. used for printf and scanf
static int uart_getchar(FILE *stream);
uint8_t uart_get_c(void); 						// gets ascii character

static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);




void ioinit (void)
{
 
// set default baud rate 
    UART0_UBRR_HIGH = (UART_BAUD_SELECT >> 8);  

    UART0_UBRR_LOW	= UART_BAUD_SELECT;  


#if defined (ATMEGA_USART)
    // enable receive, transmit and ensable receive interrupts 
    UART0_CONTROL = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE);
    // set default format, asynch, n,8,1
    #ifdef URSEL
    	UCSRC = (1<<URSEL)|(3<<UCSZ0);
    #else
    	UCSRC = (3<<UCSZ0);
    #endif 
    
#elif defined (ATMEGA_USART0 )
    // enable receive, transmit and ensable receive interrupts 
    UART0_CONTROL = (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0);
    
#endif
       
    stdout = stdin = &mystdout; //Required for printf init
	
}




static int uart_putchar(char c, FILE *stream)
{
    if (c == '\n') uart_putchar('\r', stream);
  
    loop_until_bit_is_set(UCSR0A, UDRE0);
    UDR0 = c;
    
    return 0;
}

static int uart_getchar(FILE *STREAM)
{
    while( !(UCSR0A & (1<<RXC0)) );
    return(UDR0);
}

uint8_t uart_get_c(void)
{
    while( !(UCSR0A & (1<<RXC0)) );
    return(UDR0);
}

and using the rs232-t.h file:

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

#define STATUS_LED 0

// requires the constant F_CPU to be set to the frequency of the CPU crystal 
#if !defined F_CPU
#error Constant F_CPU not set !
#endif



#if defined(__AVR_ATmega8__)  	|| defined(__AVR_ATmega16__) || 	\
	defined(__AVR_ATmega32__) 	|| defined(__AVR_ATmega8515__) || 	\
	defined(__AVR_ATmega8535__) || defined(__AVR_ATmega323__)    
	 
//
// Single USART devices
//
#define ATMEGA_USART
#define UART0_UBRR_HIGH 	UBRRH
#define UART0_UBRR_LOW 	UBRRL
#define UART0_RECEIVE_INTERRUPT   SIG_UART_RECV
#define UART0_TRANSMIT_INTERRUPT  SIG_UART_DATA
#define UART0_STATUS		UCSRA
#define UART0_CONTROL  	UCSRB
#define UART0_DATA     	UDR
#define UART0_UDRIE    	UDRIE


#elif defined(__AVR_ATmega168__)

#define ATMEGA_USART0
#define UART0_UBRR_HIGH 	UBRR0H
#define UART0_UBRR_LOW 	    UBRR0L
#define UART0_RECEIVE_INTERRUPT   SIG_USART_RECV
#define UART0_TRANSMIT_INTERRUPT  SIG_USART_DATA
#define UART0_STATUS		UCSR0A
#define UART0_CONTROL  	UCSR0B
#define UART0_DATA     	UDR0
#define UART0_UDRIE    	UDRIE0

#elif defined(__AVR_ATmega644__)

#define ATMEGA_USART0
#define UART0_UBRR_HIGH 	UBRR0H
#define UART0_UBRR_LOW 	    UBRR0L
#define UART0_RECEIVE_INTERRUPT   SIG_USART_RECV
#define UART0_TRANSMIT_INTERRUPT  SIG_USART_DATA
#define UART0_STATUS		UCSR0A
#define UART0_CONTROL  	UCSR0B
#define UART0_DATA     	UDR0
#define UART0_UDRIE    	UDRIE0

#elif 	defined(__AVR_ATmega162__) || \
	 	defined(__AVR_ATmega64__)  || \
		defined(__AVR_ATmega128__) 
//
// Dual USART devices
//
#define ATMEGA_USART0
#define UART0_UBRR_HIGH  	UBRR0H
#define UART0_UBRR_LOW   	UBRR0L
#define UART0_RECEIVE_INTERRUPT   SIG_USART0_RECV
#define UART0_TRANSMIT_INTERRUPT  SIG_USART0_DATA
#define UART0_STATUS    	UCSR0A
#define UART0_CONTROL   	UCSR0B
#define UART0_CONTROL2  	UCSR0C
#define UART0_DATA     	UDR0
#define UART0_UDRIE    	UDRIE0

#define ATMEGA_USART1
#define UART1_UBRR_HIGH  	UBRR1H
#define UART1_UBRR_LOW   	UBRR1L
#define UART1_RECEIVE_INTERRUPT   SIG_USART1_RECV
#define UART1_TRANSMIT_INTERRUPT  SIG_USART1_DATA
#define UART1_STATUS    	UCSR1A
#define UART1_CONTROL   	UCSR1B
#define UART1_CONTROL2  	UCSR1C
#define UART1_DATA     	UDR1
#define UART1_UDRIE    	UDRIE1

#else
//
// unsupported type
//
#error "Processor type not supported in uart.c !"
#endif

//
// UART Default Baud rate calculation 
//
#define UART_BAUD_RATE			115200	    // On some computers this introduces errors. 
											// Too fast to receive. perhaps a jumper/test on the atmega and using setspeed?
// #define U2X 0							// not using u2x
// u2x0 for atmega644
#define USING_U2X0 (F_CPU < 2000000ul && defined(U2X0)) 
#define BAUD_DIV (USING_U2X0? 8: 16) 

#define UART_BAUD_SELECT (((F_CPU + (UART_BAUD_RATE) * (BAUD_DIV / 2)) / ((UART_BAUD_RATE) * BAUD_DIV) - 1)) 

it still puts debug data on my C1/C0 port.

but if I add a printf statement, the output stops. I also do not get a proper output from the printf.

Now this is bothering me since the code stops completely.

Anyone idea's?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi
do we need qtouch chips to work with the lib or does only an avr do the job? microchip has a similar lib that you can use pic's to snese the keys without any external chip so does this lib do the same thing?

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Microchip has several techniques they use to implement their mTouch technology, most of them require special hardware unique to their devices. One that could be used with the AVR only requires a single comparator:

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2600&param=en535165

Leon

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ali,

Yes, only a standalone avr will do the job.
I still have not solved it. Apparantly the api is blocking the serial port (I think). But I'm not sure since I did not assign those ports to keys.
Anyway, can you start to play around with it. It might help to install the software for the demokit. You can look at the help files - it will help.

Nick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Nick.
as soon as my current project is done i will start to play with qtuch.

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi nick
i have read qtouch manual and it said i should use for example atmega8A does it realy matter that i use the A version or the older version works fine.
and what about sensor gerber files do you have any idea?

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The "A" is just a die-shrink. Should be the same otherwise.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The sensor designs can be found on the qprox website as well as in some atmel guides.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nick i think you probably have some difficulty using printf. why not just use a uart put char routine or you can use elm-chan.org xprintf stuff. it's a lot compactor and easier to use.
and there is another question. why atmel does not give the source code and made a lib for every chip and every configuration!!! are they scared that some one use their lib for using with another chip?

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have a complete url to his routines? I cannot find it.

About the proprietary code: They just bought the company. Qprox uses avr chips (as well as pic's). I think that they do not want to give an advantage to their competitors by making the source free for everyone. What I would like to see is that they create useful examples and expand the user guide. The guide is not really explaning how to use the api and chips properly.

Nick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in this link
http://elm-chan.org/cc_e.html
download •General purpose numeral output module

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Ali,

I've modified his library to a atmega168. I still have the same propblem. Before I execute the initialization of the api, printing characters works. After init of the api, its not. I think that the ports are redefined altough I never initilized port B0/B1

/* enable sensors 0..7: keys on channels 0..7 */
    qt_enable_key( CHANNEL_0, AKS_GROUP_1, 10u, HYST_6_25 );
    qt_enable_key( CHANNEL_1, AKS_GROUP_1, 10u, HYST_6_25 );
  //  qt_enable_key( CHANNEL_2, AKS_GROUP_1, 10u, HYST_6_25 );
  //  qt_enable_key( CHANNEL_3, AKS_GROUP_1, 10u, HYST_6_25 );
  //  qt_enable_key( CHANNEL_4, AKS_GROUP_1, 10u, HYST_6_25 );
  //  qt_enable_key( CHANNEL_5, AKS_GROUP_1, 10u, HYST_6_25 );
  //  qt_enable_key( CHANNEL_6, AKS_GROUP_1, 10u, HYST_6_25 );
  //  qt_enable_key( CHANNEL_7, AKS_GROUP_1, 10u, HYST_6_25 );

    /* configure the debug data reported to the PC */
    sensor_config[0] = SENSOR_CONFIG( CHANNEL_0, CHANNEL_0, SENSOR_TYPE_KEY );
    sensor_config[1] = SENSOR_CONFIG( CHANNEL_1, CHANNEL_1, SENSOR_TYPE_KEY );
    
	
//	sensor_config[2] = SENSOR_CONFIG( CHANNEL_0, CHANNEL_0, SENSOR_TYPE_UNASSIGNED );
//    sensor_config[3] = SENSOR_CONFIG( CHANNEL_0, CHANNEL_0, SENSOR_TYPE_UNASSIGNED );
//	sensor_config[4] = SENSOR_CONFIG( CHANNEL_0, CHANNEL_0, SENSOR_TYPE_UNASSIGNED );
//    sensor_config[5] = SENSOR_CONFIG( CHANNEL_0, CHANNEL_0, SENSOR_TYPE_UNASSIGNED );
//    sensor_config[6] = SENSOR_CONFIG( CHANNEL_0, CHANNEL_0, SENSOR_TYPE_UNASSIGNED );
//    sensor_config[7] = SENSOR_CONFIG( CHANNEL_0, CHANNEL_0, SENSOR_TYPE_UNASSIGNED );

Anyway, I think I have to ask Atmel directly. Any idea whom to email or phone?

Nick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well,

I found several errors. The biggest one was that there was usage of a clock prescaler. Once that one was fixed, the xprintf's are working. Now it is time to figure out the rest.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

does your hardware works?
what is the max distance that the sensors can detect your finger?

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not yet, still busy getting live data out the avr. I've got no intention to get their kit that sends the data through a usb chip into a pc. Altough nice, it still does not solve real world applications. The manual is very poor - no explanation given for many api functions.