Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832_lcd mbed
Fork of TimerInterruptExample by
main.cpp
00001 #include "mbed.h" 00002 #include "C12832_lcd.h" 00003 00004 // Definitionen 00005 #define n 9 // n ist die Ordnung des Filters, 00006 // erfordert n+1 Koeffizienten 00007 int i; 00008 float x,y; // Eingang, Ausgang 00009 int PZ; // zeigt auf Ringpuffer p 00010 int PA; // zeigt auf Koeffizienten a,b 00011 float p[n+1]; // Ringpuffer mit n Speichern (n=0 unbenutzt) 00012 float a[n+1]; // Koeffizienten 00013 00014 00015 DigitalOut myled(LED1); 00016 DigitalOut mypin(p21); 00017 C12832_LCD lcd; 00018 00019 volatile uint16_t poti, poti_f; 00020 00021 AnalogIn input(p19); 00022 void Init_Filter(); 00023 float FIR(float x); 00024 00025 //--------------------------------------------------------------------- 00026 00027 00028 void myhandler() { 00029 mypin=1; 00030 00031 // do something! 00032 poti= input.read_u16(); 00033 00034 poti_f=FIR(poti); 00035 mypin=0; 00036 00037 // clear the TIMER0 interrupt 00038 LPC_TIM0->IR = 1; 00039 00040 } 00041 00042 int main() { 00043 00044 // power up TIMER0 (PCONP[1]) 00045 LPC_SC->PCONP |= 1 << 1; 00046 00047 // reset and set TIMER0 to timer mode 00048 LPC_TIM0->TCR = 0x2; 00049 LPC_TIM0->CTCR = 0x0; 00050 00051 // set no prescaler 00052 LPC_TIM0->PR = 0; 00053 00054 // calculate period (1 interrupt every second) 00055 uint32_t period = SystemCoreClock / 4; 00056 00057 // set match register and enable interrupt 00058 LPC_TIM0->MR0 = period/10000; 00059 LPC_TIM0->MCR |= 1 << 0; // interrupt on match 00060 LPC_TIM0->MCR |= 1 << 1; // reset on match 00061 00062 // enable the vector in the interrupt controller 00063 NVIC_SetVector(TIMER0_IRQn, (uint32_t)&myhandler); 00064 NVIC_EnableIRQ(TIMER0_IRQn); 00065 00066 // start the timer 00067 LPC_TIM0->TCR = 1; 00068 00069 Init_Filter(); 00070 00071 // hang around! 00072 while(1) { 00073 lcd.cls(); 00074 lcd.locate(0,0); 00075 lcd.printf("%f",poti); 00076 00077 wait(0.2); 00078 myled = 0; 00079 wait(0.2); 00080 00081 } 00082 } 00083 void Init_Filter(){ 00084 // ***** Initialisierung am Anfang der Main-Routine 00085 // füer gleitende Mittelwertbildung: 00086 00087 a[ 0]= 0.1; 00088 a[ 1]= 0.1; 00089 a[ 2]= 0.1; 00090 a[ 3]= 0.1; 00091 a[ 4]= 0.1; 00092 a[ 5]= 0.1; 00093 a[ 6]= 0.1; 00094 a[ 7]= 0.1; 00095 a[ 8]= 0.1; 00096 a[ 9]= 0.1; 00097 00098 for (PZ=1 ; PZ<=n ; PZ=PZ+1) p[PZ]=0; //Speicher loeschen 00099 PZ = 1; // erstes Ringpufferelement definieren 00100 00101 } 00102 00103 float FIR(float x){ 00104 00105 //********* Beginn des Digitalfilters, Eingang ist x ******* 00106 00107 00108 y = a[0]*x; // Aktuellen Messwert mit Koeff. multipliz. 00109 for (PA=1 ; PA<=n ; PA = PA+1) // PA rotiert rechts herum von 1 bis n 00110 { 00111 y = y + a[PA]*p[PZ]; // Teilprodukte aufsummieren 00112 if (PZ<=1) PZ = n; else PZ = PZ -1; // PZ rotiert links herum 00113 } 00114 if (PZ<n) PZ = PZ +1; else PZ = 1; // PZ weiter fuer naechsten Messwert 00115 p[PZ] = x; // Aktuellen Messwert in Ringpuffer einschieben 00116 00117 return y; 00118 //mypin = 0; // FIR dauert 12 µs 00119 //********* Ende des Digitalfilters, Ausgang ist y ********* 00120 00121 00122 }
Generated on Fri Jul 15 2022 18:50:58 by
1.7.2
