SimpleFOClibrary
2.4.0
Loading...
Searching...
No Matches
atmega_mcu.cpp
Go to the documentation of this file.
1
#include "../hardware_api.h"
2
3
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328PB__)
4
5
#define _ADC_VOLTAGE 5.0f
6
#define _ADC_RESOLUTION 1024.0f
7
8
#ifndef cbi
9
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
10
#endif
11
#ifndef sbi
12
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
13
#endif
14
15
// function reading an ADC value and returning the read voltage
16
void
*
_configureADCInline
(
const
void
* driver_params,
const
int
pinA
,
const
int
pinB
,
const
int
pinC
){
17
_UNUSED
(driver_params);
18
19
if
(
_isset
(
pinA
) ) pinMode(
pinA
,
INPUT
);
20
if
(
_isset
(
pinB
) ) pinMode(
pinB
,
INPUT
);
21
if
(
_isset
(
pinC
) ) pinMode(
pinC
,
INPUT
);
22
23
24
GenericCurrentSenseParams
*
params
=
new
GenericCurrentSenseParams
{
25
.
pins
= {
pinA
,
pinB
,
pinC
},
26
.adc_voltage_conv = (_ADC_VOLTAGE)/(_ADC_RESOLUTION)
27
};
28
29
// set hight frequency adc - ADPS2,ADPS1,ADPS0 | 001 (16mhz/2) | 010 ( 16mhz/4 ) | 011 (16mhz/8) | 100(16mhz/16) | 101 (16mhz/32) | 110 (16mhz/64) | 111 (16mhz/128 default)
30
// set divisor to 8 - adc frequency 16mhz/8 = 2 mhz
31
// arduino takes 25 conversions per sample so - 2mhz/25 = 80k samples per second - 12.5us per sample
32
cbi(ADCSRA, ADPS2);
33
sbi(ADCSRA, ADPS1);
34
sbi(ADCSRA, ADPS0);
35
36
return
params
;
37
}
38
39
40
#endif
_configureADCInline
void * _configureADCInline(const void *driver_params, const int pinA, const int pinB, const int pinC=NOT_SET)
pinB
const int const int pinB
Definition
current_sense/hardware_specific/generic_mcu.cpp:11
pinC
const int const int const int pinC
Definition
current_sense/hardware_specific/generic_mcu.cpp:11
params
GenericCurrentSenseParams * params
Definition
current_sense/hardware_specific/generic_mcu.cpp:18
INPUT
INPUT
Definition
current_sense/hardware_specific/generic_mcu.cpp:14
pinA
const int pinA
Definition
current_sense/hardware_specific/generic_mcu.cpp:11
_UNUSED
#define _UNUSED(v)
Definition
foc_utils.h:14
_isset
#define _isset(a)
Definition
foc_utils.h:13
GenericCurrentSenseParams
Definition
current_sense/hardware_api.h:14
GenericCurrentSenseParams::pins
int pins[3]
Definition
current_sense/hardware_api.h:15
src
current_sense
hardware_specific
atmega_mcu.cpp
Generated by
1.9.8