Praktikum2_4_AMSL_v1
Dependencies: C12832_lcd mbed
Fork of TimerInterruptExample by
Revision 1:b6aa27661206, committed 2018-03-07
- Comitter:
- slueke
- Date:
- Wed Mar 07 18:56:32 2018 +0000
- Parent:
- 0:a6ea53688962
- Commit message:
- Praktikum2_4_AMSL_v1
Changed in this revision
C12832_lcd.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a6ea53688962 -r b6aa27661206 C12832_lcd.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Wed Mar 07 18:56:32 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/atthackathon/code/C12832_lcd/#3e64ca073642
diff -r a6ea53688962 -r b6aa27661206 main.cpp --- a/main.cpp Tue Feb 09 11:00:52 2010 +0000 +++ b/main.cpp Wed Mar 07 18:56:32 2018 +0000 @@ -1,19 +1,46 @@ -// Example to set up an interrupt based on the LPC TIMER0 match register, sford - #include "mbed.h" +#include "C12832_lcd.h" + +// Definitionen +#define n 9 // n ist die Ordnung des Filters, + // erfordert n+1 Koeffizienten +int i; +float x,y; // Eingang, Ausgang +int PZ; // zeigt auf Ringpuffer p +int PA; // zeigt auf Koeffizienten a,b +float p[n+1]; // Ringpuffer mit n Speichern (n=0 unbenutzt) +float a[n+1]; // Koeffizienten + DigitalOut myled(LED1); -DigitalOut irqled(LED2); +DigitalOut mypin(p21); +C12832_LCD lcd; + +volatile uint16_t poti, poti_f; + +AnalogIn input(p19); +void Init_Filter(); +float FIR(float x); + +//--------------------------------------------------------------------- + void myhandler() { + mypin=1; + // do something! - irqled = !irqled; - + poti= input.read_u16(); + + poti_f=FIR(poti); + mypin=0; + // clear the TIMER0 interrupt LPC_TIM0->IR = 1; + } int main() { + // power up TIMER0 (PCONP[1]) LPC_SC->PCONP |= 1 << 1; @@ -28,7 +55,7 @@ uint32_t period = SystemCoreClock / 4; // set match register and enable interrupt - LPC_TIM0->MR0 = period; + LPC_TIM0->MR0 = period/10000; LPC_TIM0->MCR |= 1 << 0; // interrupt on match LPC_TIM0->MCR |= 1 << 1; // reset on match @@ -39,11 +66,57 @@ // start the timer LPC_TIM0->TCR = 1; + Init_Filter(); + // hang around! while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("%f",poti); + + wait(0.2); + myled = 0; + wait(0.2); + } } +void Init_Filter(){ + // ***** Initialisierung am Anfang der Main-Routine +// füer gleitende Mittelwertbildung: + + a[ 0]= 0.1; + a[ 1]= 0.1; + a[ 2]= 0.1; + a[ 3]= 0.1; + a[ 4]= 0.1; + a[ 5]= 0.1; + a[ 6]= 0.1; + a[ 7]= 0.1; + a[ 8]= 0.1; + a[ 9]= 0.1; + + for (PZ=1 ; PZ<=n ; PZ=PZ+1) p[PZ]=0; //Speicher loeschen + PZ = 1; // erstes Ringpufferelement definieren + + } + +float FIR(float x){ + +//********* Beginn des Digitalfilters, Eingang ist x ******* + + + y = a[0]*x; // Aktuellen Messwert mit Koeff. multipliz. + for (PA=1 ; PA<=n ; PA = PA+1) // PA rotiert rechts herum von 1 bis n + { + y = y + a[PA]*p[PZ]; // Teilprodukte aufsummieren + if (PZ<=1) PZ = n; else PZ = PZ -1; // PZ rotiert links herum + } + if (PZ<n) PZ = PZ +1; else PZ = 1; // PZ weiter fuer naechsten Messwert + p[PZ] = x; // Aktuellen Messwert in Ringpuffer einschieben + + return y; + //mypin = 0; // FIR dauert 12 µs +//********* Ende des Digitalfilters, Ausgang ist y ********* + + + } \ No newline at end of file