1 z 6 26.3.2013 14:28 dspic33: Přerušení, čítače a Change Notification Přerušení Základní pojmy: přerušení maskování priority Preruseni na dspic33-fj128-mc804 15 priority levels Up to eight processor exceptions and software traps Seven user-selectable priority levels Interrupt Vector Table (IVT) with up to 126 vectors A unique vector for each interrupt or exception source Fixed priority within a specied user priority level Fixed interrupt entry and return latencies For description, see datasheet Family Reference Manual, Chapter 6 (Interrupts) Prislusne registry IFSx maintain all of the interrupt request flags. Each source of interrupt has a status bit, which is set by the respective peripherals or external signal and is cleared via software. IECx maintain all of the interrupt enable bits. These control bits are used to individually enable interrupts from the peripherals or external signals. IPCx used to set the interrupt priority level for each source of interrupt. Each user interrupt source can be assigned to one of eight priority levels. INTTREG, peripheral specific registers
2 z 6 26.3.2013 14:28 Napriklad: IEC0, bit 3 T1IE: Timer1 Interrupt Enable bit: 1 = Interrupt request enabled, 0 = Interrupt request not enabled IEC1, bit 3 CNIE: Input Change Notification Interrupt Enable bit: 1 = Interrupt request enabled, 0 = Interrupt request not enabled Ćítače Čítač je obecně logický obvod, který zajišťuje ukládá informaci o počtu proběhlých událostí. Jako periferie mikrokontroleru je touto událostí typicky vzestupná hrana hodinového signálu nebo signálu z externího vstupu. Jádrem čítače je registr, jehož bitová šířka udává počet událostí, které lze počítat. Čítače v mikrokontroleru dspic33-fj128-mc804 Mikrokontroler obsahuje celkem pět čítačů tří různých druhů. Typ A se odlišuje tím, že umožňuje běh v asynchronním režimu, dále jako zdroj čítání lze použít vestavěný oscilátor LPRC. Typy B a C mohou být zřetězeny do 32-bitových čítačů, kdy B vždy reprezentuje méně významné slovo (least-significant word) a C více významné slovo (most-significant word). Kontrolér obsahuje jeden čítač typu A (Timer1), a po dvou čítačích typu B (Timer2, Timer4) a typu C (Timer3, Timer5). Příslušné registry Registr TMRn reprezentuje stav čítače. Čtením z registru lze získat aktuální stav čítače, zápisem do registru jej lze nastavit. Registr PRn (Period Register) obsahuje hodnotu, vůči které se hodnota čítače při každé inkrementaci porovnává; v případě shody čítač generuje přerušení. Registr TnCON: obsahuje konfiguraci čítače: bit TCS (Timer Clock Source Select bit) umožňuje zvolit zdroj čítaného signálu 1 = External clock from TnCK pin 0 = Internal clock (Fosc/2)
3 z 6 26.3.2013 14:28 TON (Timer On bit) 1 = Starts the timer, 0 = Stops the timer TSIDL: Stop in Idle Mode bit: 1 = Discontinue timer operation when device enters Idle mode, 0 = Continue timer operation in Idle mode TGATE: Timer Gated Time Accumulation Enable bit: 1 = enabled, 0 = disabled (This bit is ignored when TCS = 1) TCKPS<1:0>: Timer Input Clock Prescale Select bits: 11 = 1:256 prescale value 10 = 1:64 prescale value 01 = 1:8 prescale value 00 = 1:1 prescale value TSYNC: Timer External Clock Input Synchronization Select bit: Postup nastaveni: 1 = Synchronize external clock input 0 = Do not synchronize external clock input when TCS = 0, this bit is ignored for the timer uses the internal clock nastaveni prescaleru (TCKPS v registru TnCON) spusteni casovace nastavenim TON = 1 v registru TnCONb nastaveni hodnoty registru PRn volitelne povoleni preruseni nastavenim bitu TnIE v registru IECx Change Notification slouzi k asynchronnimu osetreni udalosti, kdy dojde ke zmene stavu na vstupu
4 z 6 26.3.2013 14:28 Prislusne registry: The CNEN1 and CNEN2 registers contain the interrupt enable control bits for each of the CN input pins. Setting any of these bits enables a CN interrupt for the corresponding pins. Each CN pin also has a weak pull-up connected to it. The pull-ups act as a current source connected to the pin, and eliminate the need for external resistors when push-button or keypad devices are connected. The pull-ups are enabled separately using the CNPU1 and CNPU2 registers, which contain the control bits for each of the CN pins. Setting any of the control bits enables the weak pull-ups for the corresponding pins. Postup nastaveni: nastaveni bitu pro enable nastaveni bitu pro pull-up povoleni preruseni obsluha preruseni (_CNInterrupt) Programové použití časovače Základní varianta #define DELAY 0x6000 int main(int argc, char** argv) { /* init */ _TRISB9 = 0; // set port B as outputs T1CONbits.TCKPS = 0b11; // TMR1 prescaler // _TION possible, but ambiguous T1CONbits.TON = 1; // TMR1 on /* main program */ _LATB9 = 0; /* main loop */ while(1){ while (TMR1 < DELAY); _LATB9 = ~_LATB9; TMR1 = 0; Řízení pomocí přerušení #define DELAY 0x1000 /* * preruseni pro casovac Timer1 */ void attribute ((interrupt, no_auto_psv)) _T1Interrupt (void) { // udelej neco smyslulneho _LATB9 = ~_LATB9; // vymaz priznak preruseni IFS0bits.T1IF = 0; return; /* * main() */ int main(int argc, char** argv) {
5 z 6 26.3.2013 14:28 /* init */ _TRISB9 = 0; // set port B as outputs T1CONbits.TCKPS = 0b11; // TMR1 prescaler T1CONbits.TON = 1; // TMR1 on; _TION possible, but ambiguous _T1IE = 1; // enable TMR1 interrupt PR1 = DELAY; // set the PR value /* main program */ _LATB9 = 0; /* main loop */ while(1){ // nuda v Brne Programové použití přerušení Nastaveni preruseni // obsluha preruseni void attribute ((interrupt, no_auto_psv)) _CNInterrupt (void) {... do something // Clear interrupt flag IFS1bits.CNIF = 0; return; // change notification interrupt TRISBbits.TRISB4 = 1; CNPU1bits.CN1PUE = 0; CNEN1bits.CN1IE = 1; // global interrupt enable IFS1bits.CNIF = 0; // Clear interrupt flag IEC1bits.CNIE = 1; // Enable interrupts on CN5 Preddefinovana jmena pro jednotliva preruseni /******************************************************************************/ /* Interrupt Vector Options */ /******************************************************************************/ /* */ /* Refer to the C30 (MPLAB C Compiler for PIC24F MCUs and dspic33f DSCs) User */ /* Guide for an up to date list of the available interrupt options. */ /* Alternately these names can be pulled from the device linker scripts. */ /* */ /* dspic33f Primary Interrupt Vector Names: */ /* */ /* _INT0Interrupt _C1Interrupt */ /* _IC1Interrupt _DMA3Interrupt */ /* _OC1Interrupt _IC3Interrupt */ /* _T1Interrupt _IC4Interrupt */ /* _DMA0Interrupt _IC5Interrupt */ /* _IC2Interrupt _IC6Interrupt */ /* _OC2Interrupt _OC5Interrupt */ /* _T2Interrupt _OC6Interrupt */ /* _T3Interrupt _OC7Interrupt */ /* _SPI1ErrInterrupt _OC8Interrupt */ /* _SPI1Interrupt _DMA4Interrupt */ /* _U1RXInterrupt _T6Interrupt */ /* _U1TXInterrupt _T7Interrupt */ /* _ADC1Interrupt _SI2C2Interrupt */ /* _DMA1Interrupt _MI2C2Interrupt */ /* _SI2C1Interrupt _T8Interrupt */ /* _MI2C1Interrupt _T9Interrupt */ /* _CNInterrupt _INT3Interrupt */ /* _INT1Interrupt _INT4Interrupt */ /* _ADC2Interrupt _C2RxRdyInterrupt */ /* _DMA2Interrupt _C2Interrupt */ /* _OC3Interrupt _DCIErrInterrupt */ /* _OC4Interrupt _DCIInterrupt */ /* _T4Interrupt _DMA5Interrupt */ /* _T5Interrupt _U1ErrInterrupt */
6 z 6 26.3.2013 14:28 /* _INT2Interrupt _U2ErrInterrupt */ /* _U2RXInterrupt _DMA6Interrupt */ /* _U2TXInterrupt _DMA7Interrupt */ /* _SPI2ErrInterrupt _C1TxReqInterrupt */ /* _SPI2Interrupt _C2TxReqInterrupt */ /* _C1RxRdyInterrupt */... auth/picembc/dspic33_timers_interrupts.txt Last modified: 2013/03/26 14:27 by res