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

signal and interrupt detection on 12F

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



Joined: 28 Sep 2007
Posts: 13

View user's profile Send private message

signal and interrupt detection on 12F
PostPosted: Sun Dec 16, 2007 2:01 pm     Reply with quote

After some time offline...

I write this small code to test the interrupt that i want to use as signal detector input. I dont know if this is the wright way to do this, so i need your suggestions.Please let's take this one step at time so i ( and others ) can follow this for future use.

Code:

#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#byte ADCON0 = 0x1F
#byte ANSEL = 0x9F
#byte CMCON = 0x19

void init(){
   set_tris_a( 0b11111101 );           // GP1 OUTPUT, rest = INPUT
   setup_adc_ports( NO_ANALOGS );       // disable analog inputs
   ADCON0 = 0;                 // ADC off
   ANSEL  = 0;                  // 0 - 4 = digital

   setup_comparator( NC_NC_NC_NC );      // disable comparators
   ext_int_edge(L_TO_H);             // positive edge
   enable_interrupts(INT_EXT);       // run interrupt
   enable_interrupts(GLOBAL);       // run global
}

void main(){
 init();
     while ( TRUE ){
      output_high( PIN_A1 );  delay_ms( 350 );
      output_low ( PIN_A1 );  delay_ms( 350 ); 
  }
}


Situation:
Incoming signal is generated in one external device with smartcard.
The signal from this device is passed to GP2 at speed of 9600 b/s.
OK.

The idea was to set "read speed of the GP2" per rs232, so that this speed would be equal to speed passed from external device.
On this way, i should be able to get all correct data from external device. What do you think about that ?

So, GP2 should be able to detect interrupts ( signals ) at speed of 9600 b/s. If this signals are 100101010110101010101 this should be detected.
Or ?

With the code above i can detect interrupts but i dont know if this could be useful in my case or at speed of 9600 b/s.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 16, 2007 2:06 pm     Reply with quote

Quote:

enable_interrupts(INT_EXT); // run interrupt
enable_interrupts(GLOBAL); // run global

With the code above i can detect interrupts


You don't have an #INT_EXT routine. Because of this, if you get an
interrupt, the program will crash.
Alanis



Joined: 28 Sep 2007
Posts: 13

View user's profile Send private message

PostPosted: Wed Dec 19, 2007 3:35 pm     Reply with quote

Hi.

Am not sure how to use the interrupt routine for such problem.
To be true i dont know if this is the right way to do something like this, because i dont think that external interrupt can detect characters, bits , bytes etc. on such speeds. Maybe wrong thinking ?

Code:
#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#byte ADCON0 = 0x1F
#byte ANSEL = 0x9F
#byte CMCON = 0x19

#define LOW_LEVEL 
#define HIGH_LEVEL
#define SPEED_CHECK
#define MS_counter


void init(){
   set_tris_a( 0b11111101 );           // GP1 OUTPUT, rest = INPUT
   setup_adc_ports( NO_ANALOGS );       // disable analog inputs
   ADCON0 = 0;                 // ADC off
   ANSEL  = 0;                  // 0 - 4 = digital

   setup_comparator( NC_NC_NC_NC );      // disable comparators
   ext_int_edge(L_TO_H);             // positive edge
   enable_interrupts(INT_EXT);       // run interrupt
   enable_interrupts(GLOBAL);       // run global
}

#INT_EXT
void ext_isr(void)
{
   if() { // how to define that this is the place where program should read the first bit
   output_low(PIN_A1);   
   }
   else{
   output_high(PIN_A1);
   }
}
void main(){
   init();
      output_low( PIN_A2 );
      output_low( PIN_A3 );
      output_low( PIN_A4 );
   while (1){}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 19, 2007 3:39 pm     Reply with quote

What is the external device ?
Alanis



Joined: 28 Sep 2007
Posts: 13

View user's profile Send private message

PostPosted: Sat Dec 22, 2007 12:19 pm     Reply with quote

Please read this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=32324&highlight=
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Dec 24, 2007 10:57 am     Reply with quote

Quote:

To be true i dont know if this is the right way to do something like this, because i dont
think that external interrupt can detect characters, bits , bytes etc. on such speeds.
Maybe wrong thinking ?

Yes you are.
The external interrupt in most MCU are edge triggered. Having the choice to select with
which edge the external interrupt would be triggered, is is easily configurable to
capture the beginning of an upcoming character. For an RS232 signal level, in the TTL
side, an idle line means a steady H level, hence any action regarding a char reception
should start with a going down signal.
This is what we select with the H_to_L option in the ext_int_edge() function to
capture the front edge, the very first event.

You should know that in a Serial Data Transmition (RS232 is one of the most common
methods of sending data from one device to other) the first event that announce that
a data is coming is a START bit, a going down signal that is 1/10 of the used speed.

Setting up properly the edge to trigger the External Interrupt we can easily detect the
beginning of a data stream. But doing this, we will only get that the MCU falls immediately
in its vector interrupt when it "see" the going down of the START bit pulse, nothing more.
But remember that our goal is to catch a full char, then to get a full char, we must code
the External Interrupt handler, because actually the internal actions of the MCU was
hardware redirected here.

Fortunately the C language give us the getc() function that makes our life easier:
Code:

#INT_EXT
void EXT_isr( void )
{
   RcvdChar = getc();
   OneCharHasArrived = TRUE;
}


In this way we already captured the incoming character and copied it in the variable RcvdChar.
The variable OneCharHasArrived is used only as a flag to indicate that a new char
was received and is available.

In main() we only need to watch if such flag was setted. The receiving process was done in background.
The following is very straight forward.
Code:

char RcvdChar;
unsigned int OneCharHasArrived;
 
void main()
  {
   init();
   setup_comparator( NC_NC_NC_NC );     
   ext_int_edge(H_to_L);
   enable_interrupts(EXT_INT);
   enable_interrupts(GLOBAL);

   while(1)
      {
        // your code
            ........
            ........
       
        if(OneCharHasArrived)
          {
            putc(RcvdChar);
            OneCharHasArrived = FALSE;
          } 
      } 
}



Humberto
Alanis



Joined: 28 Sep 2007
Posts: 13

View user's profile Send private message

PostPosted: Mon Feb 25, 2008 1:16 pm     Reply with quote

Hi friends!
I got myself the 16F877 chip and am testing this on demo board.

Now i want to continue with my project in this enviroment.
What would be the first step, should i go with external interrupt or maybe some other idea ?

Any suggestion is welcome and my goal is still the same.

Alan
Alanis



Joined: 28 Sep 2007
Posts: 13

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 11:50 am     Reply with quote

Any idea about my signal detection problem ?
If someone knows how to solve this please give a tip where to start.

Thank you.
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