~rkosara/touchcore/trunk

« back to all changes in this revision

Viewing changes to touch/adc_sampling.c

  • Committer: Robert Kosara
  • Date: 2008-08-19 02:35:28 UTC
  • Revision ID: robert@eagereyes.org-20080819023528-qr55ocd9hua14eq2
Initial import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef __cplusplus
 
2
extern "C"{
 
3
#endif
 
4
 
 
5
#include <avr/io.h>
 
6
#include <stdlib.h>
 
7
#include <avr/interrupt.h>
 
8
 
 
9
#include "bitops.h"
 
10
#include "touchscreen.h"
 
11
#include "adc_sampling.h"
 
12
#include "usart.h"
 
13
 
 
14
 
 
15
 
 
16
volatile unsigned char adcCurrChan=0;
 
17
volatile unsigned char adc_delay=0;
 
18
 
 
19
////////////////////////////////////////////////
 
20
//This is our 128uS time base from timer 0
 
21
//
 
22
////////////////////////////////////////////////
 
23
SIGNAL (SIG_OVERFLOW0) //every 128us
 
24
{
 
25
 
 
26
 
 
27
if (adc_delay == ADC_DELAY_MAX)
 
28
        {
 
29
        
 
30
        adc_delay = 0; //reset the counter
 
31
        adcCurrChan++; //next channel
 
32
        if (adcCurrChan == ADC_TOTAL_CHANNELS) 
 
33
                adcCurrChan = 0; //loop back around to the first channel
 
34
 
 
35
        switch(adcCurrChan)
 
36
                {
 
37
 
 
38
                case ADC_CHAN0:
 
39
                //Touchscreen: XPLUS
 
40
                touchscreen_setup_x();
 
41
                SETBIT(ADCSRA,ADSC); //start conversion!
 
42
                break;
 
43
 
 
44
 
 
45
 
 
46
                case ADC_CHAN1:
 
47
                //Touchscreen: YMINUS
 
48
                touchscreen_setup_y();
 
49
                SETBIT(ADCSRA,ADSC); //start conversion!
 
50
                break;
 
51
 
 
52
                }//end switch
 
53
 
 
54
 
 
55
 
 
56
 
 
57
 
 
58
        }
 
59
else
 
60
        {
 
61
        adc_delay++; //increment the counter
 
62
        }
 
63
 
 
64
} //end interrupt
 
65
 
 
66
 
 
67
 
 
68
 
 
69
 
 
70
 
 
71
////////////////////////////////////////////////
 
72
//ADC sample complete!
 
73
/////////////////////////////////////////////////
 
74
SIGNAL (SIG_ADC) 
 
75
{
 
76
 
 
77
        switch(adcCurrChan)
 
78
                {
 
79
 
 
80
                case ADC_CHAN0:
 
81
                touchscreen_process_x(ADCH); 
 
82
                break;
 
83
 
 
84
                case ADC_CHAN1:
 
85
                touchscreen_process_y(ADCH);
 
86
                break;
 
87
 
 
88
 
 
89
                }
 
90
 
 
91
}
 
92
 
 
93
 
 
94
#ifdef __cplusplus
 
95
} // extern "C"
 
96
#endif
 
97
 
 
98
 
 
99
 
 
100