View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Interrupt can`t be triggered?! |
Posted: Mon Apr 08, 2013 6:50 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Mon Apr 08, 2013 7:17 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Mon Apr 08, 2013 7:47 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Mon Apr 08, 2013 9:45 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Mon Apr 08, 2013 11:48 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Mon Apr 08, 2013 12:24 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Apr 09, 2013 4:51 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Wed Apr 10, 2013 1:42 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Apr 10, 2013 3:04 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Thu Apr 11, 2013 4:12 am |
|
|
I fixed it! Thanks! |
|
![](templates/subSilver/images/spacer.gif) |
|