Page 1 of 1

Timer 9 interrupt

PostPosted: Mon Jul 18, 2016 10:20 am
by MarkoAnte
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) {
        StanjePWML3 = 0;
    else {
        StanjePWML3 = 1;
    TMR9 =0;
//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,

Re: Timer 9 interrupt

PostPosted: Tue Jul 19, 2016 3:10 pm
by MarkoAnte
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

Re: Timer 9 interrupt

PostPosted: Wed Jul 20, 2016 11:38 pm
by ric
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.

Re: Timer 9 interrupt

PostPosted: Thu Jul 21, 2016 10:16 am
by MarkoAnte
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.