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 support@ccsinfo.com

disable_interrupts(global) seems doesn't work

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







disable_interrupts(global) seems doesn't work
PostPosted: Fri Jun 12, 2009 2:58 pm     Reply with quote

I'm using 2 interruptions one for the int_timer1 and one for int_ext, the isr work perfectly. I always have pulses in INT pin(number 5) of pic12f75.

The trouble is when I try to disable the interruptions (both - I don't need them anymore) the microcontroller works strange, but if I stop to send pulses and put the pin 5 to high level the microcontroller works fine.

I need the micro work with the pulses all the time.

In order to disable the interruptions I only use :
Code:
disable_interrupts(global);

Someone can help.
Crying or Very sad

Thanks in advance.
Ttelmah
Guest







PostPosted: Fri Jun 12, 2009 3:07 pm     Reply with quote

I doubt if the problem is with the disable interrupt command. Post your compiler version, in case there is an issue with your version, but I have not seen a fault with this, in several years...

A number of comments apply though:
Where are you disabling the interrupts?. You _cannot_ use this command inside an ISR. The global flag is always re-enabled when you leave an ISR (this is done by the _hardware_), so if you were performing the disable inside the ISR, this would explain what you are seeing.
Are you sure that the supply is remaining properly stable as the pulses arrive?. Try a simple test without interrupts, but with the pulse train present.
The internal interrupt flags will still be set, if an interrupt even occurs while the master disable is 'off'. You will need to clear these flags, before turning the interrupts back on, or you will get a spurious trigger at this point.

Best Wishes
jaga
Guest







disable_interrupts(global) seems doesnt work
PostPosted: Mon Jun 15, 2009 12:23 pm     Reply with quote

Ttelmah, thank you.
I'm using the version 4.057.
Here is my code.
Code:

#include <12f675.h>                             
//#fuses INTRC_IO,NOWDT,NOMCLR,NOWP
#fuses HS,NOWDT,PUT,NOPROTECT,NOCPD,NOMCLR,BROWNOUT               
#case
//#priority int_ext

#use delay(clock=20000000)
#define PIN_TX PIN_A0
#define PIN_RX PIN_A3                   
#define PIC_RDY PIN_A1     
//#use rs232(baud=57600,xmit=PIN_TX,errors,timeout=50)       
#use rs232(baud=115200,xmit=PIN_TX,rcv=PIN_RX,errors)//,timeout=2)//
int8 odo_LSB=0,odo_MSB=0;   
int8 vel=0;
                                                                                     
//int8 cdna_dumm[5]={0};                                                           
int8 cdna[10]={0};                               
int1 flgNewData=FALSE; 
int1 flgEnviaVel=FALSE;
int8 count_cien_ms=0;               
int1 flgSendRdy=FALSE;
int1 flg_noint=FALSE;
int8 a0=0,a1=0,a2=0,a3=0,a4=0,a5=0; 
int8 cuenta2odo=0;
                                                               

//                         
//int8 odo_MSB_ante=0,acel=0;
                                                                                                 
                                                                                           
#int_ext                                                                                     
rcv_data()                                           
{                                         

//      gets(cdna);                                                                                     
   cdna[0]=getc();
   cdna[1]=getc(); 


if(cdna[1]==255)
{                             
odo_LSB=(int8)cdna[0];
odo_MSB=(int8)cdna[1];
//!vel=(int8)cdna[2]; 

//>>>
if(odo_LSB<=220)   
{
   flg_noint=FALSE;     
}
}
                     
   flgNewData=TRUE;                                 
                                                           
}                                                                         


#int_timer1   
void times()
{
   cuenta2odo++;   
   count_cien_ms++;
   if(count_cien_ms>=2)
   {                                           
      count_cien_ms=0;
      flgEnviaVel=TRUE;     
     
                       
     
   }

         
}
                                                                 
void main()                           
{
delay_ms(8000);                                                                                         

setup_adc_ports(NO_ANALOGS);                             


ext_int_edge( L_TO_H );     
enable_interrupts(INT_EXT);
             

setup_timer_1(T1_DIV_BY_8|T1_INTERNAL);//overflow cada 104.8 ms                 
enable_interrupts(INT_TIMER1);                       
output_low(PIC_RDY);                 
enable_interrupts(GLOBAL);   
                                                 
   while(1)                                                                             
   {                                                   
      //RECEPCION DE DATOS                                                   
                                                                                     
      //ENVIO DE DATOS                                                       
      if((input(PIC_RDY)==1))//&&(flgNewData==TRUE))
      {//Enviamos la ultima cadena recibida               
      cuenta2odo=0;
      //printf("HOLA\n\r");               
         if((flgEnviaVel==TRUE)&&(flg_noint==FALSE))
         {                     
            printf("%c",odo_LSB);  //odom_LSB
         //   printf("%c",odo_MSB);  //odom MSB                                                                   
            printf("%c",255);  //vel         
         //   printf("%c",255);                                                                         
            flgEnviaVel=FALSE;                     
         }
     
         while(input(PIC_RDY)==1);
                                                       
      }                       
     
      if(cuenta2odo>=7)//SE dejo en bajo la peticion de vel por 1 seg:revisar en reset de modems que pasaria
      { 
     
         
         disable_interrupts(GLOBAL);
         delay_ms(10);
     
     
         //habilñitamos bandera de recepcion de datos
         flg_noint=TRUE;
                                                                                           
      }                                       
      if(flg_noint==TRUE)                                                                     
      {                                                       
                                                                                           
                  a0=getc();
                  a1=getc();                       
                  a2=getc();                                                                             
                  a3=getc(); 
     
         while(1)                                                                               
         {                                       
            if(input(PIC_RDY)==1)
            {
                                                               
                     printf("%c",a0);
                     printf("%c",a1);
                     printf("%c",a2);                 
                     printf("%c",a3);
         
                                 
                  while(1);
            }   
         }           
     
      }
   }
}

I have not find what´s wrong with this yet. I hope someone can help.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 15, 2009 1:00 pm     Reply with quote

Hi,

What are you trying to do here?
Code:

rcv_data()                                           
{                                         

//      gets(cdna);                                                                                     
   cdna[0]=getc();
   cdna[1]=getc(); 


if(cdna[1]==255)
{                             
odo_LSB=(int8)cdna[0];
odo_MSB=(int8)cdna[1];
//!vel=(int8)cdna[2]; 

//>>>
if(odo_LSB<=220)   
{
   flg_noint=FALSE;     
}
}
                     
   flgNewData=TRUE;                                 
                                                           
}                                                                         


Getc() fetches an ASCII character between between 0 and 127 inclusive. So I am confused as to what this accomplishes:

Code:

if(cdna[1]==255)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 15, 2009 1:08 pm     Reply with quote

Quote:
Getc() fetches an ASCII character between between 0 and 127

Not true. It gets a byte from 0 to 255.

Here's part of the .LST file for a test program using the hardware UART
on an 18F452. Notice how it moves RCREG directly into 'c'.
It doesn't mask down the byte. It gets all 8 bits.
Code:
.......... c = getc();
0020:  BTFSS  PIR1.RCIF
0022:  BRA    0020
0024:  MOVFF  RCREG,c
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 15, 2009 1:25 pm     Reply with quote

PCM programmer wrote:
Quote:
Getc() fetches an ASCII character between between 0 and 127

Not true. It gets a byte from 0 to 255.

Here's part of the .LST file for a test program using the hardware UART
on an 18F452. Notice how it moves RCREG directly into 'c'.
It doesn't mask down the byte. It gets all 8 bits.
Code:
.......... c = getc();
0020:  BTFSS  PIR1.RCIF
0022:  BRA    0020
0024:  MOVFF  RCREG,c

Yes indeed...

Now I am even more confused. The UART is receiving ASCII characters right? And ASCII characters only range from 0 to 127. When will you get anything in the receive buffer that is greater than 127?

Sorry I don't know the language that the comments from the original code were written in.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 15, 2009 1:34 pm     Reply with quote

The PIC's UART sends and receives 8-bit bytes. (At least, it does this
in its normal configuration, with 1 start bit, 8 data bits, and 1 stop bit).
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