Subversion Repositories HomeAutomation

Rev

Rev 794 | Rev 796 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 794 Rev 795
Line 10... Line 10...
10
#include <config.h>
10
#include <config.h>
11
/*----------------------------------------------
11
/*----------------------------------------------
12
 * Functions
12
 * Functions
13
 * --------------------------------------------*/
13
 * --------------------------------------------*/
14
 
14
 
15
 static uint8_t currrentChannel; //Used to keep the channel of the last measurement. This is used to determine if the channel needs to be changed.
15
 static uint8_t currentChannel; //Used to keep the channel of the last measurement. This is used to determine if the channel needs to be changed.
16
 
16
 
17
uint8_t ADC_Init(void)
17
uint8_t ADC_Init(void)
18
{
18
{
19
    /* Enable AVcc as Voltage Reference */
19
    /* Enable AVcc as Voltage Reference */
20
    ADMUX |= (1<<REFS0);
20
    ADMUX |= (1<<REFS0);
Line 53... Line 53...
53
            ADMUX |= (1<<MUX0);
53
            ADMUX |= (1<<MUX0);
54
            ADMUX &= ~((1<<MUX1)|(1<<MUX2)|(1<<MUX3));
54
            ADMUX &= ~((1<<MUX1)|(1<<MUX2)|(1<<MUX3));
55
            break;
55
            break;
56
        case 2:
56
        case 2:
57
            /* Enable ADC2 */
57
            /* Enable ADC2 */
58
            ADMUX |= (1<<MUX1)|;
58
            ADMUX |= (1<<MUX1);
59
            ADMUX &= ~((1<<MUX0)|(1<<MUX2)|(1<<MUX3));
59
            ADMUX &= ~((1<<MUX0)|(1<<MUX2)|(1<<MUX3));
60
            break;
60
            break;
61
        case 3:
61
        case 3:
62
            /* Enable ADC3 */
62
            /* Enable ADC3 */
63
            ADMUX |= (1<<MUX0)|(1<<MUX1);
63
            ADMUX |= (1<<MUX0)|(1<<MUX1);
Line 82... Line 82...
82
            /* Enable ADC7 (only for TQFP package) */
82
            /* Enable ADC7 (only for TQFP package) */
83
            ADMUX |= (1<<MUX0)|(1<<MUX1)|(1<<MUX2);
83
            ADMUX |= (1<<MUX0)|(1<<MUX1)|(1<<MUX2);
84
            ADMUX &= ~(1<<MUX3);
84
            ADMUX &= ~(1<<MUX3);
85
            break;
85
            break;
86
        default:
86
        default:
-
 
87
            break;
87
            //Some kind of error message?
88
            //Some kind of error message?
88
        }
89
        }
89
       
90
       
90
        currentChannel = channel;   //Update the channel for the last measurement to the one we want this time
91
        currentChannel = channel;   //Update the channel for the last measurement to the one we want this time
91
        ADC_Get(channel);   //And do a dummy-read
92
        ADC_Get(channel);   //And do a dummy-read