Timer 9 interrupt

Timer 9 interrupt

Postby MarkoAnte » Mon Jul 18, 2016 10:20 am

Hi,
I'm using PIC32MZ2048EFM144, XC32 V1.40 and MPLABX v3.30.
I'm trying to use timers 7, 8, 9 for dead time in software generated space vector PWM. No matter what PR9 I set, I get a delay of 655,5 us = 65 550 count (at 1:1 prescaler and 100 Mhz clk) - so at overflow.
My code :
Code: Select all
void init_timer_9(void){
    T9CONbits.ON    = 0;
    T9CONbits.SIDL  = 0;
    T9CONbits.TGATE = 0;
    T9CONbits.TCKPS = 0b000;
    T9CONbits.TCS   = 0;
   
    TMR9            = 0;
    PR9             = 200; //2us
}

void __ISR(_TIMER_9_VECTOR, IPL6SRS) DTL3 (void){
    if(StanjePWML3 == 1) {
        PWM_L3_L_SET();
        StanjePWML3 = 0;
    }
    else {
        PWM_L3_H_SET();
        StanjePWML3 = 1;
    }
    T9CONCLR = _T9CON_ON_MASK;
    TMR9 =0;
    IFS1CLR =_IFS1_T9IF_MASK;
}
//form interrupt init code snippet
    //timer 9
    IPC10bits.T9IP  = 6;    //priority 6
    IPC10bits.T9IS  = 1;    //sub priority 1
    IFS1bits.T9IF   = 0;    //clear flag
    IEC1bits.T9IE   = 1;    //int enable
}



The problem is on timer 7,8,9, but I'm only debugging 9 atm. On a side note - How do I write directly to a register - eg to PR9 at Virtual adress (BF84_1020)? It may be that the register is not mapped correctly to PR9, as it is set to 0xFFFF after reset according to the datasheet.

Best regards,
Marko
MarkoAnte
 
Posts: 7
Joined: Fri Jul 15, 2016 10:18 am
PIC experience: Professional 2-5 years with MCHP products

Re: Timer 9 interrupt

Postby MarkoAnte » Tue Jul 19, 2016 3:10 pm

I have solved it, the compiler didn't call the init functions for some reason. The init was in an if statement that had an argument that did not change in an interrupt but still had to be volatile. The funny thing is after I change a couple of things and added more the the program, the argument does not have to be volatile any more :D
MarkoAnte
 
Posts: 7
Joined: Fri Jul 15, 2016 10:18 am
PIC experience: Professional 2-5 years with MCHP products

Re: Timer 9 interrupt

Postby ric » Wed Jul 20, 2016 11:38 pm

Just because something works without the volatile attribute doesn't mean it's not needed.
I'm not following your description exacty, but if something can be written to inside an interrupt, and is read from outside THAT interrupt service, then it must be declared volatile.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Timer 9 interrupt

Postby MarkoAnte » Thu Jul 21, 2016 10:16 am

The argument is change via CAN but it does not use interrupt. The CAN status is checked every cycle of the state machine. Any way it works now and it appears to be a compiler bug or something.
My mplabx is acting sketch the last couple of days. For example: Every time I hit the build & debug play button it underlines all the code in my project with the red squiggly lies. And the only way to fix SOME of it is to switch to a dsPIC and then back to a correct PIC32. It still underlines all the ISR and the #includes tho. I have also been struggling with getting my ICD3 to agree with me the first time I try to do something after I open MPLABX. I get 5-10: lost connection, end point error, could not transmit bulk data, reconnect the usb cable .... then when it start to work it works ok. It works until I by mistake don't stop the program with the stop button and then recompile and start debug but directly click on the recompile and debug button. Then it brakes again.
MarkoAnte
 
Posts: 7
Joined: Fri Jul 15, 2016 10:18 am
PIC experience: Professional 2-5 years with MCHP products


Return to Timers

Who is online

Users browsing this forum: No registered users and 1 guest

cron