INTERRUPT PROBLEM

Re: INTERRUPT PROBLEM

Postby Manoj » Wed May 02, 2018 12:02 pm

Thanks for your continuous support.
okay its working now. the scope I was using to measure frequency was defective,and the multimeter was also unable to show as it was over range.
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: INTERRUPT PROBLEM

Postby Manoj » Fri May 11, 2018 5:14 am

Hi ,it is me again. I need some advice. I am using pic24fj256gb110 . I am using Tmr4 & 5 in 32 bit.the preiod will start from 125000 And will decrese to 6 by 10% in each step . it will give a frequency of 64hz to 1280000Hz.
my Fcy=16000000hz,so F=1/((1/16000000)*PR*Prescalar )=>1333333Hz. at prescalr=1and pr=12 .but the preiod is always stuck when it is come to 28. It is not decreasing below 28.
I used debugging method to confirm it.
I tried using a prescalar of 8 ,in this case at pr=1. F should be 2000000.but again pr is stuck in 11.
Do you know Why is this hapening?
Code:-
Code: Select all
   #define STEPWAVE               PORTAbits.RA7
  //  #define STEPWAVE                                    LATAbits.LATA7

void FrequencyScan(void)
   {
   //if (previous_option!=current_option)//first entry to this routine

   TRISA=(TRISA&0b1111111101111111);

      T4CON=0x00;       // Stop any 16/32-bit Timer4 operation
      T5CON=0x00;
      TMR5=0x00;          // Clear contents of the TMR4 and TMR5
      TMR4=0x00;
      PR5=preiod-65536;
      PR4=preiod;
      IPC7bits.T5IP2=TRUE;
      T4CONbits.T32=TRUE;      //enable 32 bit mode
      IFS1bits.T5IF   = 0;       // Clear Timer 5 Interrupt Flag
      IEC1bits.T5IE=TRUE;         // Enable Timer5 interrupt
      T4CONbits.TON=TRUE;         // Start Timer


   if(preiod<=125000 && preiod>20000)
      {
      preiod=preiod-preiod*.1;
      }
   
   else if(preiod<=20000 && preiod>10)
      {
      preiod=preiod-preiod*0.05;
      }
/*   else
      {
      if(c<=10000.99)
         {
         preiod=preiod-1;
         
         }
      else{}
      }
*/
f=(1/(preiod*0.000000125));
c=f/64;
//DELAY();

   if(c<10000.00)
      {
         DispL1(13);
      Put_String_LCD("Running");
         DispL2(0);
      sprintf(LCDBuf,"F=%.2f          ",c);   
      Put_String_LCD(LCDBuf);
            
      }
      else
      {
      DispL1(0);
      Put_String_LCD(" Done           ");
      DispL2(0);
      Put_String_LCD("F=640000         ");   
      LongDelay(8);         
      mainstate = OPENING_SCREEN;      
      }
}
 
void __attribute__((__interrupt__, auto_psv)) _T5Interrupt( void )
{
    if (IFS1bits.T5IF)
    {
        // Clear the interrupt flag
            IFS1bits.T5IF   = 0;
         OverflowFlag      = TRUE;
         Error3         = TRUE;
         SyncFlag      = 0;
         STEPWAVE=STEPFLG;
         STEPFLG=!STEPFLG;
         if (KEY_PRESSED == S2)
                     {
                     KEY_PRESSED=0;
                     mainstate = OPENING_SCREEN;      
                     return;
                     }                  
         KEY_PRESSED=0;
    }
}

thans in advance
Last edited by ric on Sun May 13, 2018 12:28 am, edited 1 time in total.
Reason: Added "code" tags around the code.
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: INTERRUPT PROBLEM

Postby ric » Sun May 13, 2018 12:32 am

Please put code tags around your code when you post it. That is (code) before, and (/code) after, but use [] instead of ()
You seem to be freely mixing integer variables and floating point constants, which can have unexpected results.
Rather than "var * 0.05", use "var / 20"
Be very careful of constants like ".1", I'm not sure that will always be interpreted as "0.1" .

I'm not that familiar with this family of PICs, so there could be some more glaring problems I've missed.
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: INTERRUPT PROBLEM

Postby AussieSusan » Mon May 14, 2018 4:12 am

I do find your code very hard to understand as there are large portions commented out and the layout is all over the place. Also without seeing how the functions are called it is hard to understand exactly what they are doing. For example, I can't see what the 'preiod' variable is supposed to be doing in the 'FrequencyScan' function: you set up the timer and then alter the value, but without knowing what happens after that (is the function called again and if so from where and under what conditions)
I have not experienced any sort of issues with the timers just stopping in the way you describe on these devices.
I suggest that you set up the timer so that it simply times down and is then reset. In other words get a very basic operation of the timer working.
Next start adding in some of the complications to your code (e.g. toggling the output pin) a small section at a time. If the timer stops counting again then you knwo that the error is in the last small section of code that you have added which makes it much easier to solve the problem.
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: INTERRUPT PROBLEM

Postby Manoj » Sat May 19, 2018 6:40 am

I am trying to initialize preiod as hex. So is it okay to initialize it like this?
int preiod=0xFFFE;

there is no error showing when I compile the code.
but it is not entering the loop,i.e.
if( preiod>0x7530)
{
f=(1/(preiod*0.000000125));
preiod=preiod-preiod/10;
c=f/64;
DispFirstLine(0);
Put_String_LCD("FrequencyScanRunning");
DispSecLine(0);
sprintf(LCDBuf,"Frequency:%.2f ",c);
Put_String_LCD(LCDBuf);
}


it is jumping to staright to the else loop, i.e.
else
{

DispFirstLine(0);
Put_String_LCD("Done, Results... ");
DispSecLine(0);
Put_String_LCD(" Press S1 to return ");
}

But when I am declearing preiod as float value,i.e.
float preiod=65535;
there is no problem.
I also tried
int preiod=65535;
it is not also helping
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: INTERRUPT PROBLEM

Postby AussieSusan » Mon May 21, 2018 4:40 am

You need to consider the actual size of the variables you are using.
An 'int' is a signed 16-bit value. That means the maximum positive value it can take is 32767 - 65535 is WAY too big. If you try to initialise an int with 0xfffe, it will be set to -2!
'float' variables are always signed but they have a larger domain and so 65535 can be correctly represented as a positive number.
Whoever be careful with using floating point values (and constants) as they can take a lot of processing time. Your calculation for 'f' would be better as '8000000ul/preiod' - at least that way you can do they calculation as integer values and make some use of the integer divide instructions.
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: INTERRUPT PROBLEM

Postby Manoj » Mon May 21, 2018 8:05 am

My oscillator is 8 Mhz, system clk is 32 mhz, 48 mhz is used for usb module
Is there any way to increase the system clock frequency more than 32 MHZ?

This the code for my pic24fj256gb110:-
_CONFIG3(GWRP_OFF) // GWRP_OFF : General Segment Write Protect: Writes to program memory are allowed
_CONFIG2(FNOSC_PRIPLL & FCKSM_CSECMD & POSCMOD_HS & PLL_96MHZ_ON & PLLDIV_DIV2) // Primary HS OSC with PLL, Clock Switching Enabled with Failsafe Monitor, USBPLL /2
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF & ICS_PGx2 ) // JTAG off, watchdog timer off

Thanks.
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: INTERRUPT PROBLEM

Postby ric » Mon May 21, 2018 12:35 pm

Page 3 of the datasheet says the maximum speed is 16 MIPs at 32MHz, so the answer is obviously "No, you cannot run the CPU at 48 MHz".
Do you really need more than 16 MIPS?
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: INTERRUPT PROBLEM

Postby Manoj » Mon May 21, 2018 12:38 pm

okay thnku
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: INTERRUPT PROBLEM

Postby AussieSusan » Tue May 22, 2018 3:16 am

Before spinning off on another problem (clock speed), have you solved the problem with not entering the 'then' clause o the 'if' statement?
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

PreviousNext

Return to PIC24

Who is online

Users browsing this forum: No registered users and 14 guests

cron