blob: 67ac0d594a1606115863c484b708bfba97823add [file] [log] [blame]
Luigi Santivetti2e35a2e2019-11-17 22:26:14 +00001/*
2 cpu_map_adc.h - ADC pin mapping configuration file
3 Part of Grbl
4
5 Copyright (c) 2019 Luigi Santivetti <luigi.santivetti@gmail.com>
6
7 Grbl is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Grbl is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Grbl. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21/* The cpu_map_adc.h files serve as a central pin mapping selection file for the ADC
22 module for different processor types or alternative pin layouts. This version of
23 Grbl officially supports only the Arduino Mega328p. */
24
25#ifndef cpu_map_adc_h
26#define cpu_map_adc_h
27
28#ifdef CPU_MAP_ATMEGA328P
29
30// Define ADC registers
31#define ADC_ST1_REG ADCSRA
32#define ADC_ST2_REG ADCSRB
33#define ADC_MUX_REG ADMUX
34#define ADC_HGH_REG ADCH
35#define ADC_LOW_REG ADCL
36#define ADC_PRR_REG_cpu PRR // Outside the ADC block
37
38// Set to enable in hardware conversion triggering (auto-trigger)
39#define ADC_ST1_TRIGGER_BIT ADATE
40// Set to start a conversion (manual-trigger)
41#define ADC_ST1_START_BIT ADSC
42// Set to left adjust converted values as follows:
43// +--------------------------+--------------------------+
44// | ADCH | ADCL |
45// +--------------------------+--------------------------+
46// | X X X X X X X X | | <- 8 bit value
47// | X X | X X X X X X X X | <- 10 bit value
48// +--------------------------+--------------------------+
49// | 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 |
50// | ^MSB LSB^ | ^MSB LSB^ |
51// +--------------------------+--------------------------+
52#define ADC_ST1_LEFTSHIFT_BIT ADLAR
53// Set to enable interrupt
54#define ADC_ST1_IRQ_BIT ADIE
55// Set to switch the ADC on (it requires also power saving to be disabled)
56#define ADC_ST1_ENABLE_BIT ADEN
57// Set to enable power reduction
58#define ADC_PRR_cpu_PRADC_BIT PRADC
59
60// Supported modes. Modes are set at compile time. It isn't possible to
61// switch mode dynamically. Add more modes below.
62#define ADC_ST2_MODEFR_MASK ((1<<ADTS2)|(1<<ADTS1)|(1<<ADTS0))
63
64// Reference voltage
65#define ADC_MUX_REFAVC_MASK (1<<REFS0)
66#define ADC_MUX_REFALL_MASK ((1<<REFS1)|ADC_MUX_REFAVC_MASK)
67#define ADC_MUX_REFEXT_MASK ADC_MUX_REFALL_MASK
68
69// Onboard inputs
70#define ADC_MUX_CHTMP_MASK (1<<MUX3)
71#define ADC_MUX_CHALL_MASK (ADC_MUX_CHTMP_MASK|(1<<MUX2)|(1<<MUX1)|(1<<MUX0))
72#define ADC_MUX_CHGND_MASK ADC_MUX_CHALL_MASK
73#define ADC_MUX_CHVBG_MASK (ADC_MUX_CHTMP_MASK|(1<<MUX2)|(1<<MUX1))
74
75// Optional free inputs
76#define ADC_MUX_CH0_MASK ADC_MUX_CHALL_MASK
77#define ADC_MUX_CH1_MASK (1<<MUX0)
78#define ADC_MUX_CH2_MASK (1<<MUX1)
79#define ADC_MUX_CH3_MASK ((1<<MUX1)|(1<<MUX0))
80#define ADC_MUX_CH4_MASK (1<<MUX2)
81#define ADC_MUX_CH5_MASK ((1<<MUX2)|(1<<MUX0))
82#define ADC_MUX_CH6_MASK ((1<<MUX2)|(1<<MUX1))
83#define ADC_MUX_CH7_MASK ((1<<MUX2)|(1<<MUX1)|(1<<MUX0))
84
85// Available clocks
86#define ADC_ST1_CLKALL_MASK ((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0))
87#define ADC_ST1_125KHZ_MASK ADC_ST1_CLKALL_MASK
88#define ADC_ST1_250KHZ_MASK ((1<<ADPS2)|(1<<ADPS1))
89#define ADC_ST1_500KHZ_MASK ((1<<ADPS2)|(1<<ADPS0))
90#define ADC_ST1_001MHZ_MASK (1<<ADPS2)
91#define ADC_ST1_002MHZ_MASK ((1<<ADPS1)|(1<<ADPS0))
92#define ADC_ST1_004MHZ_MASK (1<<ADPS1)
93#define ADC_ST1_008MHZ_MASK ADC_ST1_CLKALL_MASK
94
95#endif // CPU_MAP_ATMEGA328P
96#endif // cpu_map_adc_h