|
|
View previous topic :: View next topic |
Author |
Message |
Guard
Joined: 20 Jan 2005 Posts: 43
|
Help BUG in #INT_DEFAULT |
Posted: Sun Feb 20, 2005 7:45 am |
|
|
PCWH 3.218
I am using interrupt comparator by #INT_DEFAULT
( The wizard doesn't function and Device Edit wrong memory location!)
I know the #Int_default has a bug!!( My application does't function....)
I can update my complier the next month only!
The bug is fixed by next release
3.219 A bug in #INT_DEFAULT is fixed affecting code located outside page 0
I have 3.218 , somebody can help me?
Thank |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Feb 20, 2005 9:21 am |
|
|
Write your own #int_global handler and check the bits yourself. Search the board for examples. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Feb 20, 2005 7:12 pm |
|
|
Quote: | I know the #Int_default has a bug!!( My application does't function....)
I can update my complier the next month only!
The bug is fixed by next release
3.219 A bug in #INT_DEFAULT is fixed affecting code located outside page 0 | So, what is your problem? You have one month of of update time left, and v3.219 has been released. What is stopping you from downloading this version?
Are you sure the above bug fix will solve your problem?
Quote: | 3.219 Some device definitions updates for the newest parts | This might fix your problem with the 'Device Edit wrong memory location'.
Or....
Post your code and we will have a look at it. |
|
|
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Mon Feb 21, 2005 4:11 am |
|
|
My is an annual update. I am not secure for 3.219
I am using #INT_global only for comparator interrupt (C2).
The other interrupts are disabled, but the program counter jump always to location 0004h
#INT_GLOBAL
void isr() {
#asm
MOVWF save_w
SWAPF status,W
BCF status,5
BCF status,6
MOVWF save_status
#endasm
if(C2IE_BIT) // Is the interrupt enabled ?
{
DAC=100; //for debug
if (MC2out==0) // or C2IF_bit
{
C1ON=0;
C2ON=0;
Fan Off
SMCON =0 ;
}
DAC=51; // for debug
C2IF_BIT=0;
}
#asm
SWAPF save_status,W
MOVWF status
SWAPF save_w,F
SWAPF save_w,W
#endasm |
|
|
Ttelmah Guest
|
|
Posted: Mon Feb 21, 2005 5:13 am |
|
|
So, where do you expect the program counter to go?. 0004H, is where an interrupt will vector to. This is correct...
Your code is 'fussy'. If you only have the C2 interrupt enabled, the only way the code can be reached is by this interrupt, hence there is no need to test for the interrupt enabled bit. However if any other interrupt can be enabled, then you _must_ clear the interrupt flag for this before exiting the routine, or the code will be stuck in an infinite loop, constantly jumping back to address 4. It sounds as if this may be what is actually happening to you.
You also need to look through the entire assembler generated for the interrupt, and verify that no other registers are used by your code, and if any are, save their contents. You are saving W, and status, but if (for instance), 'Fan off' involves accessing an array, then the pointer registers will also need to be saved. As soon as you use int_global, you become responsible for saving everything, and must check just what is needed.
If you cannot see what is happening, post the definitions you are using for all the interrupt flags/registers, the definitions for 'fan off', the definitions of the numeric values used, what processor is involved, and the code you are using to initialise the interrupt.
Best Wishes |
|
|
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Thu Feb 24, 2005 10:26 am |
|
|
HI,
I tested newly my code , but it doesn't work
I am using PSMC ( C2 and C1 input to PSMC ) and comparator 2 interrupt
Code: |
#include <16C781.h>
#use delay(clock=10000000)
#fuses NOWDT,HS, PUT,NOPROTECT,MCLR, BROWNOUT, BORV42,
#define ON =1;
#define OFF =0;
int save_w;
#locate save_w=0x7f
int save_status;
#locate save_status=0x30
#byte status = 3
#bit zero_flag = status.2
static short int Camp;
/////////////////////////////////////////////////////////////
#byte Port_b = 0x06
#byte portA=5
#byte TRISB =0x86
#byte TRISA =0x85
#byte OPTION=0x81
#bit RBPU=OPTION.7
#byte wpub =0x95
#byte Ansel =0x9d
#bit Fan = Port_B.7
#bit Gate = Port_B.6
#bit pin_datain = Port_B.5
#bit pin_dataout = Port_B.4
///////////////////////////////// A/D
#byte REFCON=0X9B
#byte ADCON0 =0X1F
#bit ADCSL= ADCON0.6
#bit ADCSH= ADCON0.7
#bit CHSH= ADCON0.5
#bit CHSM= ADCON0.4
#bit CHSL= ADCON0.3
#bit GODONE= ADCON0.2
#bit CHS3= ADCON0.1
#bit ADON= ADCON0.0
#byte ADCON1=0X9F
#bit VCFGH= ADCON1.5
#bit VCFGL= ADCON1.4
//////////////////////////////////////// Comparator interrupt
#byte INTCON = 0x0b
#bit PEIE = INTCON.6
#bit C2IF_BIT = 0x0C.5
#bit C1IF_BIT = 0x0C.4
#bit C2IE_BIT = 0x8C.5
#bit C1IE_BIT = 0x8C.4
#bit LVDIE=0x8c.7
//////////////////////////////////////// PSMC
// Registro di controllo 0
#byte PSMCCON0 = 0x111
#bit SMCCLH = 0x111.7
#bit SMCCLL = 0x111.6
#bit MINDCH = 0x111.5
#bit MINDCL = 0x111.4
#bit MAXDCH = 0x111.3
#bit MAXDCL = 0x111.2
#bit DCH = 0x111.1
#bit DCL = 0x111.0
/////////////////////////////////////// PSMC
// Registro di controllo 1
#byte PSMCCON1 = 0x112
#bit SMCON = 0x112.7
#bit S1APOL = 0x112.6
#bit S1BPOL = 0x112.5
#bit NOTUSED = 0x112.4
#bit SCEN = 0x112.3
#bit SMCOM = 0x112.2
#bit PWMPSM = 0x112.1
#bit SMCCS = 0x112.0
//////////////////////////////////////// OP
#byte OPACON = 0x11C
#byte CALCON = 0x110 //
#bit CMPEN=OPACON. 6
#bit OPAON=OPACON. 7
#bit GBWP =OPACON. 0
#bit CAL = CALCON.7
#bit CALREF= CALCON.5
/////////////////////////////////////// Registri del comparatore 1
#byte CM1CON0 = 0x119 // comparatore 1
#bit C1ON = 0X119.7
#bit C1OUT = 0X119.6
#bit C1OE = 0X119.5
#bit C1POL = 0X119.4
#bit C1SP = 0X119.3
#bit C1R = 0X119.2
#bit C1CHH = 0X119.1
#bit C1CHL = 0X119.0
/////////////////////////////////////// comparator 2
#bit MC2OUT = 0x11b.6
#byte CM2CON0 = 0x11A // comparatore 2
#bit C2ON = 0X11A.7
#bit C2OUT = 0X11A.6
#bit C2OE = 0X11A.5
#bit C2POL = 0X11A.4
#bit C2SP = 0X11A.3
#bit C2R = 0X11A.2
#bit C2CHH = 0X11A.1
#bit C2CHL = 0X11A.0
#bit C2IF=0xc.5
////////////////////////////////////// DAC
#byte DAC = 0x11E
#byte DACON0 = 0x11F
#byte ANSEL = 0x9D
#bit DAON= DACON0.7
#bit DAOE= DACON0.6
#bit DARSH= DACON0.1
#bit DARSL= DACON0.0
///////////////////////////////////////////////// Prototipe
short int calibrate_opamp_internal(void) ;
void setup_comparators (void);
void setup_psmc(void);
void setup_dac(void);
void config_mcu(void);
////////////////////////////////////////////////Interrupt
#INT_GLOBAL
void isr() {
#asm
MOVWF save_w
SWAPF status,W
BCF status,5
BCF status,6
MOVWF save_status
#Endasm
if (C2IF_BIT)
{
C2IF_BIT=0;
DAC=100; // For debug
do {
pin_dataout=1; //Error Code
delay_cycles(50);
pin_dataout=0;
delay_cycles(50);
} while(1); //Wait for POWER OFF
}
/*
DAC=100;
if (MC2out==0)
{
#asm
BCF C2IF_BIT
BCF C1ON
BCF C2ON
BCF SMCON
#endasm
}
DAC=51;
*/
#asm
SWAPF save_status,W
MOVWF status
SWAPF save_w,F
SWAPF save_w,W
#endasm
}
////////////////////////////////////////////
void main()
{
Config_mcu(); //
Gate off
Fan Off
pin_dataOut Off
do
{
Camp = calibrate_opamp_internal(); // opAMP
}
while ( !Camp);
setup_dac();
setup_comparators ();
setup_psmc();
delay_ms(100);
Dac =51;
PEIE=1;
C2IE_BIT =1;
enable_interrupts(GLOBAL);
do {
delay_ms(1);
} while (1);
}
void Config_mcu(void)
{
TRISA=255;
TRISB=37;
WPUB=0;
RBPU=1;
setup_adc_ports( sAN2| sAN3|sAN4| sAN6|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_32);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
setup_timer_1(T1_DISABLED);
C2IE_BIT =0; // Interrupt
C1IE_BIT =0; // Interrupt
LVDIE=0;
PEIE=0;
disable_interrupts(INT_AD);
disable_interrupts(INT_RB);
disable_interrupts(INT_EXT);
disable_interrupts(INT_RTCC);
disable_interrupts(GLOBAL);
}
void setup_dac()
{
DARSL=0;
DARSH=0;
DAOE =1;
DAC =0;
DAON =1;
}
void setup_comparators (void)
{
// Config comparator 1
C1CHH =1; // AN6
C1CHL =0;
C1R =0;
C1POL=0;
C1SP =1;
C1OE =1;
C1ON =1;
// Config comparator 2
C2CHH =1; // AN6
C2CHL =0;
C2R =0;
C2SP =1;
C2POL=0;
C2OE =0;
C2ON =1; //
}
void setup_psmc(void)
{
SMCON =0 ;
DCH = 0; // not used PSM
DCL = 0; // not used
MAXDCH = 0; //50% D.C.
MAXDCL = 0;
MINDCH = 0; // 0% D.C.
MINDCL = 0;
SMCCLH = 0;
SMCCLL = 0;
SMCCS =1 ;
PWMPSM =1 ; // PWM MODE
SMCOM =0 ; // SINGLE OUTPUT
SCEN =0;
S1APOL =0;
S1BPOL =0;
SMCON =1 ;
}
boolean calibrate_opamp_internal(void)
{
CMPEN =0;
OPAON =1;
GBWP =0;
CALREF=0;
delay_ms(20);
CAL=1;
while( bit_test(CALCON, 7) );
if (bit_test(CALCON, 6))
return(false);
else
return(true);
}
|
|
|
|
|
|
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
|