From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../mi2/Termin4/Termin4Aufgabe1.c | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Bachelor/Mikroprozessorsysteme2/mi2/Termin4/Termin4Aufgabe1.c (limited to 'Bachelor/Mikroprozessorsysteme2/mi2/Termin4/Termin4Aufgabe1.c') diff --git a/Bachelor/Mikroprozessorsysteme2/mi2/Termin4/Termin4Aufgabe1.c b/Bachelor/Mikroprozessorsysteme2/mi2/Termin4/Termin4Aufgabe1.c new file mode 100644 index 0000000..67b220d --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/mi2/Termin4/Termin4Aufgabe1.c @@ -0,0 +1,80 @@ +// Lösung zur Aufgabe Termin4 +// Aufgabe 1 +//**************************** +// Zeiger auf Peripherie +// Messen der Periodendauer einer angelegten Frequenz +// +// von: Manfred Pester +// vom: 06. August 2003 + +#include "../h/pio.h" +#include "../h/tc.h" +#include "../h/pmc.h" + +// für die Initialisierung des Zähler TC4 + +#define TC4_INIT TC_CLKS_MCK2 | TC_LDBSTOP | TC_CAPT | TC_LDRA_RISING_EDGE | TC_LDRB_RISING_EDGE + + +int main(void) +{ + volatile int captureRA1; + volatile int captureRB1; + volatile int capturediff1; + volatile float Periodendauer1; + volatile int captureRA2; + volatile int captureRB2; + volatile int capturediff2; + volatile float Periodendauer2; + volatile int c1=18030/1.09; + volatile int c2=40; + volatile float masse; + + StructPMC* pmcbase = PMC_BASE; + StructPIO* piobaseA = PIOA_BASE; + StructPIO* piobaseB = PIOB_BASE; + StructTC* tcbase4 = TCB4_BASE; + StructTC* tcbase5 = TCB5_BASE; + + pmcbase->PMC_PCER = 0x06f80; // Clock PIOA, PIOB, Timer5, Timer4, Timer1 einschalten + +// Periodendauer der Waagensignale messen +// Signal aud TIOA4 ca. 16kHz entspricht ca. einer Periodendauer von 62,5us +// durch den Teiler von 32 ergeben sich ca. 2ms +// Zähler mit positiver Flanke starten + + //piobaseA->PIO_PDR = 0x090; + piobaseA->PIO_PDR = (1<TC_CCR = TC_CLKDIS; + tcbase4->TC_CMR = TC4_INIT; + tcbase4->TC_CCR = TC_CLKEN; + tcbase4->TC_CCR = TC_SWTRG; + + tcbase5->TC_CCR = TC_CLKDIS; + tcbase5->TC_CMR = TC4_INIT; + tcbase5->TC_CCR = TC_CLKEN; + tcbase5->TC_CCR = TC_SWTRG; + + piobaseB-> PIO_PER = KEY3; + + while(piobaseB->PIO_PDSR & KEY3) + { + tcbase4->TC_CCR = TC_SWTRG; + tcbase5->TC_CCR = TC_SWTRG; + while (!( tcbase4->TC_SR & TC_LDBSTOP)); // Capture Register B wurde geladen Messung abgeschlossen + captureRA1 = tcbase4->TC_RA; // + captureRB1 = tcbase4->TC_RB; + capturediff1 = abs(captureRB1) - abs(captureRA1); + Periodendauer1 = abs(capturediff1) / 12.5; // Zeit in us + while (!( tcbase5->TC_SR & TC_LDBSTOP)); // Capture Register B wurde geladen Messung abgeschlossen + captureRA2 = tcbase5->TC_RA; // + captureRB2 = tcbase5->TC_RB; + capturediff2 = abs(captureRB2) - abs(captureRA2); + Periodendauer2 = abs(capturediff2) / 12.5; // Zeit in us + + masse = c1 * ((Periodendauer1 / Periodendauer2) -1) -c2; + + } + + return 0; +} -- cgit v1.2.3