ADC revised
This commit is contained in:
parent
f9e56b44f3
commit
2d26632f41
|
@ -11,9 +11,9 @@ set label at 4,7 'U_{GS} [V] = 480' left
|
|||
set label at 3,13 'U_{GS} [V] = 500' left
|
||||
set label at 2,22 'U_{GS} [V] = 520' left
|
||||
set label at 1,32 'U_{GS} [V] = 540' left
|
||||
set label at 0,41 'U_{GS} [V] = 560' left
|
||||
set label at 0,42 'U_{GS} [V] = 580' left
|
||||
set label at 0,42 'U_{GS} [V] = 600' left
|
||||
set label at 0,39 'U_{GS} [V] = 560' left
|
||||
set label at 0,39 'U_{GS} [V] = 580' left
|
||||
set label at 0,39 'U_{GS} [V] = 600' left
|
||||
unset output
|
||||
set terminal qt
|
||||
unset output
|
||||
|
|
BIN
driver/main
BIN
driver/main
Binary file not shown.
|
@ -158,9 +158,9 @@ void testFunktionen()
|
|||
|
||||
int main()
|
||||
{
|
||||
testFunktionen();
|
||||
//testFunktionen();
|
||||
//kennlinieZweiterQuadrant();
|
||||
//kennlinieErsterQuadrant();
|
||||
kennlinieErsterQuadrant();
|
||||
|
||||
std::cout << "Schluss." << std::endl;
|
||||
}
|
||||
|
|
BIN
driver/test_plot
BIN
driver/test_plot
Binary file not shown.
Binary file not shown.
|
@ -5,23 +5,28 @@ void ADU::init() volatile
|
|||
// externe Referenz an AREF
|
||||
ADMUX = 0;
|
||||
|
||||
// ADC aktiviert, prescaler = 128
|
||||
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
|
||||
// ADC aktiviert, Interruptbetrieb, prescaler = 128
|
||||
ADCSRA = _BV(ADEN) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
|
||||
}
|
||||
|
||||
void ADU::handleConversionComplete() volatile
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
uint16_t ADU::getValue(uint8_t channel) volatile
|
||||
{
|
||||
while(active);
|
||||
active = true;
|
||||
|
||||
// lege Kanal fest
|
||||
ADMUX = (ADMUX & 0xE0) | channel;
|
||||
|
||||
// starte Konvertierung
|
||||
ADCSRA |= _BV(ADSC);
|
||||
|
||||
// warte Konvertierungszeit ab
|
||||
_delay_us(13 * 1000000 * 128 / F_CPU + 1);
|
||||
|
||||
// warte auf Ende
|
||||
while(ADCSRA & _BV(ADSC));
|
||||
// warte auf Ende der Konvertierung
|
||||
while(active);
|
||||
|
||||
return ADCW;
|
||||
}
|
||||
|
|
|
@ -2,14 +2,29 @@
|
|||
#define ADC_H
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include <stdint.h>
|
||||
|
||||
class ADU
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Konfiguriert die ADC Register
|
||||
*/
|
||||
void init(void) volatile;
|
||||
uint16_t getValue(uint8_t) volatile;
|
||||
|
||||
/**
|
||||
* Behandlungsroutine für ADC interrupt
|
||||
*/
|
||||
void handleConversionComplete(void) volatile;
|
||||
|
||||
/**
|
||||
* Startet eine AD Konvertierung, wartet auf Abschluss und liefert Ergebnis
|
||||
* \param channel Auswahl des ADC Kanals (0-7), Kanal 6 und 7 sind Poti R36 und R37
|
||||
*/
|
||||
uint16_t getValue(uint8_t channel) volatile;
|
||||
|
||||
private:
|
||||
volatile bool active = false;
|
||||
};
|
||||
|
||||
#endif // ADC_H
|
||||
|
|
|
@ -15,3 +15,8 @@ ISR(SPI_STC_vect)
|
|||
{
|
||||
spi.handleTransfer();
|
||||
}
|
||||
|
||||
ISR(ADC_vect)
|
||||
{
|
||||
adu.handleConversionComplete();
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ void SPI::init() const volatile
|
|||
// Konfiguriere DMUX DDRs
|
||||
DDRD |= _BV(DMUX1) | _BV(DMUX2) | _BV(DMUX3);
|
||||
|
||||
// aktiviere SPI, Master Modus, SPI Modus 0
|
||||
// aktiviere SPI, Interruptbetrieb, Master Modus, SPI Modus 0
|
||||
// F_SPI = F_CPU / 2 (prescaler 2)
|
||||
SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPIE);
|
||||
SPSR = _BV(SPI2X) | _BV(SPIF);
|
||||
SPSR = _BV(SPI2X);
|
||||
|
||||
// waehle keinen SPI Slave aus
|
||||
setAdr(SPIADR::NONE);
|
||||
|
|
Loading…
Reference in a new issue