CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Interrupt can`t be triggered?!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Interrupt can`t be triggered?!
PostPosted: Mon Apr 08, 2013 6:50 am     Reply with quote

Hi! I`m using dsPIC30F5015. As the datasheet and the header file says there are 2 FAULT interrupt sources - PIN 42 and 43. I tried to make a program using this FAULT interrupts.
Code:

#INT_FAULTA
void FAULTAInterrupt()
{
      /*
      actions
      */
}

void main()
{
     enable_interrupts(GLOBAL);
     enable_interrupts(INT_FAULTA);
     while(1);
}


Here is the problem! Independently what I`m passing to the PIN_FAULTA(42) - 5V or 0V, I can`t trigger this interrupt?
Can you tell me what I`m doing wrong?
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 7:17 am     Reply with quote

You should post a small compilable program. None of us can really help as we don't know what 'actions' take place within your ISR, let alone the real setup of the PIC.
I don't think a lot of users code dsPICs but there are things 'common' to all PICs.
As your 'code' stands...nothing there would indicate if the ISR fires or not.
Also nothing (like a 'I'm alive LED') to say the PIC is running...

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 7:47 am     Reply with quote

You are misunderstanding the chip.
The fault pins, are for use with the PWM, allowing you to shutdown the PWM, when a hardware error occurs on this. They are not available as interrupt inputs, unless the PWM is enabled, and setup to handle this condition. The interrupt occurs when the PWM is shutdown by the pin. It is the PWM that triggers the interrupt, after it is shutdown by the fault input.
This is why if you look in the interrupt list. you have:
"FLTA – PWM Fault A" as the interrupt.
INT1, and INT2, are available on the same pins, if you want to trigger an interrupt using these.

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 9:45 am     Reply with quote

OK! I`m using 3 PWM channels and here is the most significant part of my code:
Code:

//I`m using this interrupt to update the PWM duty cycle
        ENABLE_INTERRUPTS(INTR_GLOBAL);
        ENABLE_INTERRUPTS(INT_PWM1);
        ENABLE_INTERRUPTS(INT_FAULTA);

   setup_motor_pwm(1,MPWM_FREE_RUN,1,1,1200);
   setup_motor_pwm(2,MPWM_FREE_RUN,1,1,1200);
   setup_motor_pwm(3,MPWM_FREE_RUN,1,1,1200);

   set_motor_unit(1,1,MPWM_ENABLE ,10,10);
   set_motor_unit(1,2,MPWM_ENABLE ,10,10);
   set_motor_unit(1,3,MPWM_ENABLE,10,10);

   set_motor_pwm_duty(1,1,0);
   set_motor_pwm_duty(1,2,0);
   set_motor_pwm_duty(1,3,0);

        while(1)
        {
              //main program
        }


So I check again in the header file (30F5015.h) and the faults are called
#define INT_FAULTA 66
#define INT_FAULTB 68
I my case when I turn on this interrupt(ENABLE_INTERRUPTS(INT_FAULTA);) it doesn`t trigger.
Any suggestions what do I haveto do?
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 11:48 am     Reply with quote

You are not setting the PWM to use fault handling.
Look at the options:
Code:

#define MPWM_FAULTA_LA_HA     0x0700
#define MPWM_FAULTA_LA_HI     0x0500
#define MPWM_FAULTA_LI_HA     0x0600
#define MPWM_FAULTA_LI_HI     0x0400
#define MPWM_FAULTB_LA_HA     0x7000
#define MPWM_FAULTB_LA_HI     0x5000
#define MPWM_FAULTB_LI_HA     0x6000
#define MPWM_FAULTB_LI_HI     0x4000
#define MPWM_FAULT_NO_CHANGE 0x0000

These set what happens when the fault input triggers.
Only once these are set, can you get an interrupt response.

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 12:24 pm     Reply with quote

I tried this! But when I pass low level voltage to the fault input, the PWM exists are set to the chosen level and I can`t bring them back to normal state. I just don`t enter in the #INT_FAULTA function. Should I have to clean any flags?
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Tue Apr 09, 2013 4:51 am     Reply with quote

What compiler version are you on?.

Quite possible (likely) there is a problem with your chip and the version....

The basic behaviour should be:

1) It won't work till you select a mode through the PWM settings.
2) If you select the 'no_change' option in the setup, this allows you to treat the pin as an interrupt. It'll trigger and not affect the PWM.
3) Sometimes the chips will wake in the state for '2', but most don't.
4) Alternatively you can trigger the pins to go to a preset state and trigger the interrupt.

Now given you are seeing the outputs correctly set to the 'fault' state, it should trigger.

I suspect there is a problem in the configuration for the interrupts on your chip. Yours looks to be a fairly old compiler, since the 'GLOBAL' interrupt was dropped some time ago, and now uses 'INTR_GLOBAL' on the DS PIC's.
It was so long ago that 'GLOBAL' was dropped, that I'd be surprised if it did work....

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Wed Apr 10, 2013 1:42 am     Reply with quote

I`m using v4.134 and it`s INTR_GLOBAL. My fault!
I run some simulations with MPLAB SIM and everything is working fine, but when I load it to the board it`s not working!
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Wed Apr 10, 2013 3:04 am     Reply with quote

My guess then would be one register not being initialised, and defaulting to a different value in MPLAB, to the real chip.
Only way to find this, unless you have ICD capabilities, would be to make a list of ever register involved in this, read them, and print the contents out on a serial, both in MPLAB, and the real chip.
Horrible type of one.... :(

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Apr 11, 2013 4:12 am     Reply with quote

I fixed it! Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group