-
Notifications
You must be signed in to change notification settings - Fork 30
/
utils.cpp
43 lines (34 loc) · 1.49 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
utils.cpp
Copyright (C) 2017 Niryo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utils.h"
#include <Arduino.h>
// analogRead takes < 30 micros instead of > 400 micros (10 bits precision)
void init_analog_fast_read()
{
ADC->CTRLA.bit.ENABLE = 0; // Disable ADC
while( ADC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization
ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV128 | // Divide Clock by 128
ADC_CTRLB_RESSEL_10BIT;
ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_1 | // 1 sample
ADC_AVGCTRL_ADJRES(0x00ul); // Adjusting result by 0
ADC->SAMPCTRL.reg = 0x00; // Sampling Time Length = 0
ADC->CTRLA.bit.ENABLE = 1; // Enable ADC
while( ADC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization
}
void setup_fan()
{
pinMode(FAN_PIN, OUTPUT);
delay(10);
}