• AVR Freaks

Hot!OC1 and interrupts

Author
rorlich
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2010/09/22 15:14:17
  • Location: 0
  • Status: offline
2010/09/30 08:43:40 (permalink)
0

OC1 and interrupts

Hello i'm trying to setup the OCxCON for continues pulses

i used the sample code on the pic 32 data sheet and put a break point inside the interrupt but for some reason the program never get inside the interrupt.

void __ISR(  _OUTPUT_COMPARE_1_IRQ , ipl4) OC1_IntHandler(void)
{
    // clear interrupt flag and exit
    //mOC1ClearIntFlag();
IFS0CLR = 0x00000080;
} // 

main ()
{
    
     initEX16();
     T2CON = 0x0000; // 36Mhz

OC1CON=0;
OC1CON=0x0005;


OC1R = 899;
OC1RS = 899;
PR2 = 899; 

IFS0CLR=0x80;
IEC0SET=0x80;
IPC1SET=0x0030000;
IPC1SET=0x00000003;

T2CONSET = 0x8000;
OC1CONSET=0x8000;

    while( 1)
    {   
       
       
    } 
} // main

Thanks!


#1

2 Replies Related Threads

    JohnPIA
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/08/29 23:26:45
    • Location: Netherlands
    • Status: offline
    Re: OC1 and interrupts 2019/02/07 01:36:55 (permalink)
    0
    Its an old question, but the answer is simple: When using timers as source, the timer isr needs to be used for this.
    Enable timer IE and you can add/change frequency/duty within the isr.
     
    Also! I've seen lots of wrong information in Microchips datasheets, like "enabling T3 ISR" with 0x1000, which is input compare (not even output compare ..), which should be 0x4000.
    Also they mention 0x40 as OC1 ISr, which is IC1 and should be 0x80 (output compare ISR).
    I can't imagine your still busy whith this, but if anyone have issues, I've some code examples.
     
    Greetz John
    #2
    Howard Long
    Super Member
    • Total Posts : 664
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: OC1 and interrupts 2019/02/07 02:28:04 (permalink)
    0
    I'm not sure that's what the OP meant?
     
    You can certainly generate an OC interrupt, with or without having a Timer interrupt. In mode 5 (dual compare continuous pulse, i.e. high on OC1R==TIMER2, and low on OC1RS==TIMER2). The ISR triggers on OC1RS==TIMER2.
     

    #include <xc.h>
    #include <sys/attribs.h>
    void __ISR(_TIMER_2_VECTOR,IPL2AUTO) Timer2ISR(void)
    {
    IFS0CLR=_IFS0_T2IF_MASK;
    }
    void __ISR(_OUTPUT_COMPARE_1_VECTOR,IPL2AUTO) OC1ISR(void)
    {
    IFS0CLR=_IFS0_OC1IF_MASK;
    }
    void main(void)
    {
    // Global interrupt setup
    INTCONbits.MVEC=1;
    __builtin_enable_interrupts();

    // Timer 2 setup
    PR2=10000;
    TMR2=0;
    IPC2bits.T2IP=2;
    IPC2bits.T2IS=0;
    IFS0bits.T2IF=0;
    IEC0bits.T2IE=1;
    T2CONbits.ON=1;

    // OC1 setup
    OC1CONbits.OCM=0b101; // Continuous pulses
    OC1R=2000;
    OC1RS=7000;
    IPC1bits.OC1IP=2;
    IPC1bits.OC1IS=0;
    IFS0bits.OC1IF=0;
    IEC0bits.OC1IE=1;
    OC1CONbits.ON=1;

    while (1)
    {
    Nop();
    }
    return;
    }

    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5