Hallo,
ich habe ein Problem mit der Verwendung des output compare Interruppts.
Ich möchte gern eine LED während der High-Phase des OC2-Pin einschalten.
Dazu verwende ich das timer- und das oc-interrupt. Im Timerinterrupt,
wenn der OC2-Pin auf high gesetzt wird, schalte ich die LED ein und im
Output compare Interrupt schalte ich diese aus.
Allerdings gelange ich nicht in die Interruptroutine des OC. Prinzipiell
läuft die OC-Unit, denn mit dem Oszi kann ich an dem OC2-Pin eine PWM
messen und die sieht auch so aus, wie ich das erwarte. Nur wird eben das
compare match nicht ausgeführt.
Kann mir wer helfen? Ist bestimmt ein einfacher dummer Fehler
meinerseits...
uC: PIC32MX795F512L
compiler: XC32 v1.21 (latest release)
IDE: MPLAB X
edit: es scheint, als ob das interrupt flag OC2IF nicht gesetzt wird.
wenn ich in der while(1)-Schleife das Bit polle, wackelt auch keine
LED....
1 | int main(void) {
|
2 |
|
3 | //SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
|
4 | SYSTEMConfig(SYS_FREQ,0);
|
5 | INTEnableSystemMultiVectoredInt();
|
6 |
|
7 | // init IO-pins to used functionality
|
8 | initIO();
|
9 | // init PWMTimer
|
10 | // clear interrupts-flag, init interrupts and timer
|
11 | initPWMTimer();
|
12 | // enable hardware PWM on PWMH
|
13 | initHardwarePWMOnPWMH(500);
|
14 | enableHardwarePWMOnPWMH();
|
15 | // start basic Timer
|
16 | startPWMTimer();
|
17 | // now do periodic stuff
|
18 | while(1);
|
19 | return (EXIT_SUCCESS);
|
20 | }
|
PWM ist nur ein Platzhalter für den entsprechenden Timer. Wird im Makro
dann ausgetauscht (aktuell Timer2)
mTPWMCearIntFlag() == mT2ClearIntFlag() usw.
1 | void initPWMTimer(){
|
2 | mTPWMClearIntFlag();
|
3 | ConfigIntTimerPWM(TPWM_INT_ON | TPWM_INT_PRIOR_7 | TPWM_INT_SUB_PRIOR_0);
|
4 | OpenTimerPWM(TPWM_OFF | TPWM_PS_1_1 , PWM_TIMER_PR);
|
5 | }
|
6 |
|
7 | void initHardwarePWMOnPWMH(int dutyCycle){
|
8 | OC2CON = 0x0000;
|
9 | // write to PRy is already done
|
10 | // write duty cycle to OC2RS and OC2R
|
11 | // config operation mode
|
12 | OpenOC2(OC_OFF | OC_IDLE_CON | OC_TIMER_MODE16 | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, dutyCycle, dutyCycle);
|
13 | // clear interrupt flag and enable interrupts
|
14 | mOC2ClearIntFlag();
|
15 | ConfigIntOC2(OC_INT_ON | OC_INT_PRIOR_3 | OC_INT_SUB_PRI_0);
|
16 | // set TMRy is already done
|
17 | // enable Timer will be done later
|
18 | }
|
ISR's
1 | // all implemented ISRs
|
2 | void __ISR(_TIMER_PWM_VECTOR, IPL7SRS) TimerPWMHandler(void){
|
3 |
|
4 | mTPWMClearIntFlag();
|
5 |
|
6 | LED5_TOGGLE;
|
7 | LED4_ON;
|
8 |
|
9 | }
|
10 |
|
11 | void __ISR(_OUTPUT_COMPARE_2_VECTOR, IPL3AUTO) OutputCompare2Handler(void){
|
12 | mOC2ClearIntFlag();
|
13 | LED4_OFF;
|
14 | }
|