Maximilian Krieg
Wissen, Technik & Erfahrungen
Wissen, Technik & Erfahrungen
Wissen, Technik & Erfahrungen

/ Aufgabe 1
// von:
// vom:
//
#include "../h/pmc.h"
#include "../h/tc.h"
#include "../h/pio.h"
#include "../h/aic.h"
// Timer3 initialisieren
void Timer3_init( void )
{
StructTC* timerbase3 = TCB3_BASE; // Basisadressse TC Block 1
StructPIO* piobaseA = PIOA_BASE; // Basisadresse PIO B
timerbase3->TC_CCR = TC_CLKDIS; // Disable Clock
// Initialize the mode of the timer 3
timerbase3->TC_CMR =
TC_ACPC_CLEAR_OUTPUT | //ACPC : Register C clear TIOA
TC_ACPA_SET_OUTPUT | //ACPA : Register A set TIOA
TC_WAVE | //WAVE : Waveform mode
TC_CPCTRG | //CPCTRG : Register C compare trigger enable
TC_CLKS_MCK8; //TCCLKS : MCKI / 8
// Initialize the counter:
timerbase3->TC_RA = 31250; //Flanke hoch
timerbase3->TC_RC = 62500; //Flanke runter
// Start the timer :
timerbase3->TC_CCR = TC_CLKEN ; //Clock enable
timerbase3->TC_CCR = TC_SWTRG ; //Enable Software Trigger
piobaseA->PIO_PER = (1<<PIOTIOA3) ; // PIO A kontrolliert Timer3
piobaseA->PIO_OER = (1<<PIOTIOA3) ; // als Ausgang
piobaseA->PIO_CODR = (1<<PIOTIOA3) ; // einschalten
}
int main(void)
{
StructPMC* pmcbase = PMC_BASE; // Basisadresse des PMC
StructPIO* piobaseA = PIOA_BASE; // Basisadresse PIO A
StructPIO* piobaseB = PIOB_BASE; // Basisadresse PIO B
pmcbase->PMC_PCER = 0x6200; // Peripheral Clocks einschalten für PIOA,PIOB,TC3
// ab hier entsprechend der Aufgabestellung ergänzen
//**************************************************
Timer3_init(); // Timer3 initialisieren
while(1)
{
}
return 0;
}
Power Management
Berechnung der Zähler RA und RC:
| MCK | Takt(Hz) | MCK/X | Periodendauer | Counter Duration (sec) | Überlauf/sec | Frequenz | Register-Wert |
| 1 | 25.000.000 | 25000000 | 0,00000004 | 0,00262144 | 381,4697266 | 50 | 500000 |
| 2 | 25.000.000 | 12500000 | 0,00000008 | 0,00524288 | 190,7348633 | 50 | 250000 |
| 8 | 25.000.000 | 3125000 | 0,00000032 | 0,02097152 | 47,68371582 | 50 | 62500 |
| 32 | 25.000.000 | 781250 | 0,00000128 | 0,08388608 | 11,92092896 | 50 | 15625 |
| 128 | 25.000.000 | 195312,5 | 0,00000512 | 0,33554432 | 2,980232239 | 50 | 3906,25 |
| 1024 | 25.000.000 | 24414,0625 | 0,00004096 | 2,68435456 | 0,37252903 | 50 | 488,28125 |
// Lösung zu Termin3
// Aufgabe 1
// von:
// vom:
//
#include "../h/pmc.h"
#include "../h/tc.h"
#include "../h/pio.h"
#include "../h/aic.h"
void taste_irq_handler (void) __attribute__ ((interrupt));
// Interruptserviceroutine für die Tasten SW1 und SW2
void taste_irq_handler (void)
{
StructPIO* piobaseB = PIOB_BASE; // Basisadresse PIO B
StructAIC* aicbase = AIC_BASE; //Basisadresse AIC
// ab hier entsprechend der Aufgabestellung ergänzen
// *************************************************
StructPIO* piobaseA = PIOA_BASE;
// Einschalten
if(!(piobaseB->PIO_PDSR & 0x10)) { // Taste 2 zum einschalten
piobaseA->PIO_PDR = (1PIO_PER = (1PIO_ISR; // Interrupt beenden
}
// Timer3 initialisieren
void Timer3_init( void )
{
StructTC* timerbase3 = TCB3_BASE; // Basisadressse TC Block 1
StructPIO* piobaseA = PIOA_BASE; // Basisadresse PIO B
timerbase3->TC_CCR = TC_CLKDIS; // Disable Clock
// Initialize the mode of the timer 3
timerbase3->TC_CMR =
TC_ACPC_CLEAR_OUTPUT | //ACPC : Register C clear TIOA
TC_ACPA_SET_OUTPUT | //ACPA : Register A set TIOA
TC_WAVE | //WAVE : Waveform mode
TC_CPCTRG | //CPCTRG : Register C compare trigger enable
TC_CLKS_MCK8; //TCCLKS : MCKI / 8
// Initialize the counter:
timerbase3->TC_RA = 31250; //Flanke hoch
timerbase3->TC_RC = 62500; //Flanke runter
// Start the timer :
timerbase3->TC_CCR = TC_CLKEN ; //Clock enable
timerbase3->TC_CCR = TC_SWTRG ; //Enable Software Trigger
piobaseA->PIO_PER = (1AIC_ICCR= 1 << 14; // InterruptPIOB löschen aicbase->AIC_SVR[PIOB_ID] = (unsigned int)taste_irq_handler;
aicbase->AIC_SMR[PIOB_ID] = 0x7; // Priorität
aicbase->AIC_IECR= 1 << 14; // InterruptPIOB einschalten piobaseB->PIO_IER= KEY1|KEY2; // Interrupt innerhalb PIOB erlauben ////
pmcbase->PMC_PCER = 0x6200; // Peripheral Clocks einschalten für PIOA,PIOB,TC3
// ab hier entsprechend der Aufgabestellung ergänzen
//**************************************************
Timer3_init(); // Timer3 initialisieren
while(1)
{
}
return 0;
}
Termin 6:
Ausgabe des Signals: