搜索
bottom↓
回复: 3
打印 上一主题 下一主题

初试QTOUCH,居然连引脚上都没有测到波形

[复制链接]

出0入0汤圆

跳转到指定楼层
1
发表于 2010-6-25 13:34:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
想试试看QTOUCH,选M48的CPU  4.0的库,修改IAR样例程序(初次学用IAR,有错误请批评)。修改后程序编译通过,但是用示波器测量IO,居然连波形都没有。下面是我的程序,如有错误请不吝赐教。

#include <ioavr.h>
#include <intrinsics.h>
#include "touch_api.h"          

static void init_system( void );                //initialise host app, pins, watchdog, etc
static void init_timer_isr( void );                //configure timer ISR to fire regularly
static void qt_set_parameters( void );         //Assign the parameters values to global configuration parameter structure
static void config_sensors(void);
static void config_keys(void);


#pragma vector=TIMER1_COMPA_vect
__interrupt static void timer_isr( void );

/*  The timing information for timer to fire periodically to measure touch  */
#define TICKS_PER_MS                1381u
#define MEASUREMENT_PERIOD_MS       25u          

#define GET_SENSOR_STATE(SENSOR_NUMBER) qt_measure_data.qt_touch_status.sensor_states[(SENSOR_NUMBER/8)] & (1 << (SENSOR_NUMBER % 8))
//#define GET_ROTOR_SLIDER_POSITION(ROTOR_SLIDER_NUMBER) qt_measure_data.qt_touch_status.rotor_slider_values[ROTOR_SLIDER_NUMBER]

/* This configuration data structure parameters if needs to be changed will be
   changed in the qt_set_parameters function */
extern qt_touch_lib_config_data_t qt_config_data;
extern qt_touch_lib_measure_data_t qt_measure_data;        //touch output - measurement data
extern int16_t qt_get_sensor_delta( uint8_t sensor);//Get sensor delta values

static volatile uint8_t time_to_measure_touch = 0u;                //flag set by timer ISR when it's time to measure touch
static volatile uint16_t current_time_ms_touch = 0u;          // current time, set by timer ISR

int main( void )
{
    /*status flags to indicate the re-burst for library*/
    uint16_t status_flag = 0u;
    uint8_t burst_flag = 0u;   
   
    /* initialise host app, pins, watchdog, etc */
    init_system(); DDRD = 0xFF;


    config_sensors();
    qt_init_sensing();                 //initialise touch sensing
    qt_set_parameters( );        //Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user
    init_timer_isr();                 //configure timer ISR to fire regularly

    /*  Address to pass address of user functions   */
    /*  This function is called after the library has made capacitive measurements,
    *   but before it has processed them. The user can use this hook to apply filter
    *   functions to the measured signal values.(Possibly to fix sensor layout faults)    */
    qt_filter_callback = 0;

    __enable_interrupt();//enable interrupts

    for( ; ; ) //loop forever
    {
        if( time_to_measure_touch )
        {
                 PORTD|=(1u<<PORTD6);
            time_to_measure_touch = 0u;          // clear flag: it's time to measure touch

            do{
                status_flag = qt_measure_sensors( current_time_ms_touch ); //one time measure touch sensors
                                if(GET_SENSOR_STATE(1)!=0)PORTD|=(1u<<PORTD5);
                                else PORTD&=~(1u<<PORTD5);
                burst_flag = status_flag & QTLIB_BURST_AGAIN;
                if (burst_flag!= 0u)
                {
                    /*Time critical host application code goes here*/
                }
            }while (  burst_flag) ;
        }
                else PORTD&=~(1u<<PORTD6);
    /*  Time Non-critical host application code goes here  */
    }
}

/*============================================================================
Name    :   init_timer_isr
------------------------------------------------------------------------------
Purpose :   configure timer ISR to fire regularly
Input   :   n/a
Output  :   n/a
Notes   :
============================================================================*/

static void init_timer_isr( void )
{
    OCR1A = ( TICKS_PER_MS * MEASUREMENT_PERIOD_MS);        //set timer compare value (how often timer ISR will fire)
        TIMSK1 |= (1u << OCIE1A);//enable timer ISR
    TCCR1B |= (1u << CS11);        //timer prescaler = system clock / 8
    TCCR1B |= (1u << WGM12);//timer mode = CTC (count up to compare value, then reset)       
}


/*============================================================================
Name    :   init_system
------------------------------------------------------------------------------
Purpose :   initialise host app, pins, watchdog, etc
Input   :   n/a
Output  :   n/a
Notes   :
============================================================================*/

static void init_system( void )
{
    /*  run at 4MHz (assuming internal clock is set to 8MHz)*/
//    CLKPR = 0x80u;
//    CLKPR = 0x01u;
        MCUCR |= (1u << PUD);        //disable pull-ups
}

/*============================================================================
Name    :   timer_isr
------------------------------------------------------------------------------
Purpose :   timer 1 compare ISR
Input   :   n/a
Output  :   n/a
Notes   :
============================================================================*/
#pragma vector=TIMER1_COMPA_vect
__interrupt static void timer_isr( void )
{
    time_to_measure_touch = 1u;                                // set flag: it's time to measure touch
    current_time_ms_touch += MEASUREMENT_PERIOD_MS;        //update the current time
}


/*============================================================================
Name    :   qt_set_parameters
------------------------------------------------------------------------------
Purpose :   This will fill the default threshold values in the configuration
            data structure.But User can change the values of these parameters .
Input   :   n/a
Output  :   n/a
Notes   :   initialize configuration data for processing
============================================================================*/

static void qt_set_parameters( void )
{
    /*  This will be modified by the user to different values   */
    qt_config_data.qt_di              = DEF_QT_DI;
    qt_config_data.qt_neg_drift_rate  = DEF_QT_NEG_DRIFT_RATE;
    qt_config_data.qt_pos_drift_rate  = DEF_QT_POS_DRIFT_RATE;
    qt_config_data.qt_max_on_duration = DEF_QT_MAX_ON_DURATION;
    qt_config_data.qt_drift_hold_time = DEF_QT_DRIFT_HOLD_TIME;
    qt_config_data.qt_recal_threshold = DEF_QT_RECAL_THRESHOLD;
}

/*============================================================================
Name    :   config_sensors
------------------------------------------------------------------------------
Purpose :   Configure the sensors
Input   :   n/a
Output  :   n/a
Notes   :   n/a
============================================================================*/
static void config_sensors(void)
{
    config_keys();
}
/*============================================================================
Name    :   config_keys
------------------------------------------------------------------------------
Purpose :   Configure the sensors as keys only
Input   :   n/a
Output  :   n/a
Notes   :   n/a
============================================================================*/
static void config_keys(void)
{
    /*  enable sensors 0..3: keys on channels 0..3  */
    qt_enable_key( CHANNEL_0, NO_AKS_GROUP, 10u, HYST_6_25 );
    qt_enable_key( CHANNEL_1, NO_AKS_GROUP, 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 );

#if(QT_NUM_CHANNELS >= 8u)
    /*  enable sensors 4..7: keys on channels 4..7   */
//    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 );
#endif
#if(QT_NUM_CHANNELS >= 12u)
    /*  enable sensors 8..11: keys on channels 4..7   */
//    qt_enable_key( CHANNEL_8, AKS_GROUP_1, 10u, HYST_6_25 );
//    qt_enable_key( CHANNEL_9, AKS_GROUP_1, 10u, HYST_6_25 );
//    qt_enable_key( CHANNEL_10, AKS_GROUP_1, 10u, HYST_6_25 );
//    qt_enable_key( CHANNEL_11, AKS_GROUP_1, 10u, HYST_6_25 );
#endif   
#if (QT_NUM_CHANNELS >= 16u)
    /*  enable sensors 12..15: keys on channels 8..15    */
//    qt_enable_key( CHANNEL_12, AKS_GROUP_1, 10u, HYST_6_25 );
//    qt_enable_key( CHANNEL_13, AKS_GROUP_1, 10u, HYST_6_25 );
//    qt_enable_key( CHANNEL_14, AKS_GROUP_1, 10u, HYST_6_25 );
//    qt_enable_key( CHANNEL_15, AKS_GROUP_1, 10u, HYST_6_25 );
#endif

}



IAR (原文件名:p1.jpg)


IAR配置 (原文件名:p2.jpg)

出0入0汤圆

2
 楼主| 发表于 2010-6-25 13:52:49 | 只看该作者
如果将B口设置成SNSK1,C口设置成SNS1则B口上可以看到波形,不过有个问题我只设置了两个键,为什么是PB0/PB1/PB3看到输出波形?
SNSK1=B
SNS1=C

出0入296汤圆

3
发表于 2010-6-28 09:51:18 | 只看该作者
Assembler里面也有宏要设置……

出0入0汤圆

4
 楼主| 发表于 2010-6-28 17:19:06 | 只看该作者
是的我将Assembler里也设置成如下,就OK了。
SNSK1=C
SNS1=C
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-20 09:44

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表