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
16void* _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
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
void * _configureADCInline(const void *driver_params, const int pinA, const int pinB, const int pinC=NOT_SET)
const int const int const int pinC
GenericCurrentSenseParams * params
#define _UNUSED(v)
Definition foc_utils.h:14
#define _isset(a)
Definition foc_utils.h:13