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

Question about interrupt flag

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



Joined: 16 Sep 2008
Posts: 51

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

Question about interrupt flag
PostPosted: Sun Jan 11, 2009 4:08 am     Reply with quote

Hello 2 all !

I've been researching for a few days, the following problem :
Is there a way to monitor the interrupt flag in ccs c ? i.e. let's say that i have the need for a interrupt at a specified value like 842 uS (for example) but i don't want to do nothing in that interrupt, just to monitor the interrupt flag.
So, when the interrupt flag is set, i increase a counter variable.
If the counter variable reaches a value of "2" then i know that 1,84 ms have passed from the first initialization of the timer.

Is this possible ?

Thank you very much !!

P.S.: I'm using a pic 18f452 and ccs compiler version 4.057.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jan 11, 2009 6:01 am     Reply with quote

Increase a counter is more than doing nothing, I think. The most obvious solution would be to do just this an interrupt service routine. Alternatively you can use no ISR, monitor the interrupt flag (e.g. in your main loop), count the event and reset the flag manually. But why?
Andrew83



Joined: 16 Sep 2008
Posts: 51

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

PostPosted: Sun Jan 11, 2009 6:14 am     Reply with quote

Hello FvM !

So...i am trying to build a IR transmitter using a pic.

Taking as an example the RC5 code :
-a logic "1" bit is represented by a 842 uS high and a 842 uS low.
-a logic "0" bit is represented by a 842 uS low and a 842 uS high.

Let's say i wanted to represent the following command : 01110.
I don't want the pic to stop whatever he was doing to service this process(of converting the commnad into a train of pulses).

I was interested to know if i could get de 842uS period without using #INT_TIMER0 and by just counting the number of times the flag of the timer sets, and how can i do this (if it is possible).
Thank's !!
Andrew83



Joined: 16 Sep 2008
Posts: 51

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

PostPosted: Sun Jan 11, 2009 6:22 am     Reply with quote

Currently, my serial transmitter does the following:

1. Receives a character form serial port.
2.Translates this character into binary form, and saves the result into a globaly declared string.
3.When the conversion is complete, i enable de timer0 interrupt, go through the string and modelate the waveform (e.g. translate the series of zeros and ones into IR pulses).

I think that this course of action makes sense.

However, i'm searching for a more direct way of translating the binary string into IR pulses.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jan 11, 2009 7:17 am     Reply with quote

As you mentioned RC5: How do you generate the around 36 kHz modulation? Normally, RC5 transmission is using a fixed number of carrier cycles instead of an additional timer. You should be able to find many PIC RC5 transmission examples.

Apart from this, you simply didn't tell why you want to avoid a timer interrupt. It's also unclear, in which code you want to poll the timer IR flag and count the events. Obviously, this code has to be executed periodically and faster than a timer period. But then it's possible, of course.
Andrew83



Joined: 16 Sep 2008
Posts: 51

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

PostPosted: Sun Jan 11, 2009 7:32 am     Reply with quote

Quote:
How do you generate the around 36 kHz modulation?


The answer is PWM module. To modulate a 842uS High @ 36 KHz i'm using the pwm module. I'm mantaining the pwm module ON, for the duration of the timer0 period ( i.e. when timer0 overflows, it disables also the PWM module).

Quote:
you simply didn't tell why you want to avoid a timer interrupt.

The answer is, because i don't want to use the string array to save the binary form of the command. I want to be able to modulate the waveform as i convert the character form the serial port .
Let me give you an example code:

Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <string.h>

void main()
{
  char c,d,i,buffer[9];
while(1)         
{
c=getc();
for(i = 0; i < 8; i++)
{
if(c & 0x80)
{
d='1';
}
else
{
d='0';
}
c <<= 1;
buffer[i]=d;
}
buffer[8]=0;
printf("%s \n\r",buffer);
}
}

I want to be able to do the conversion in the "if(c & 0x80)" statement.
For it to work, i think it is crucial that i know the state of the timer0 interrupt flag.

Quote:
You should be able to find many PIC RC5 transmission examples.

99% of the examples that are out there, are about RC5 receiver (i.e. receiving and decoding signals from a remote control).

Thank you very much for your input, FvM ! Smile
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jan 11, 2009 8:57 am     Reply with quote

The suggestion was to count the timer events, not to do the output itself in the ISR. It would be still possible with your code. But as you intend to do nothing but poll the timer flag, you can do with no problems.

Code:
#bit TMR1IF = 0xF9E.0
while (!TMR1IF);
TMR1IF=0;
Andrew83



Joined: 16 Sep 2008
Posts: 51

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

PostPosted: Sun Jan 11, 2009 9:03 am     Reply with quote

Thank you very much FvM ! I appreciate your patience and interest!
muhibraza1



Joined: 26 Jul 2013
Posts: 23

View user's profile Send private message

PostPosted: Sun Sep 28, 2014 11:13 pm     Reply with quote

hello Andrew83 !

you can also do it with the CCS built in functions interrupt_active() and clear_interrupts()....

Like this :

Code:


while(!interrupt_active(INT_TIMER1));
clear_interrupts(INT_TIMER1);



This way you dont even need to locate a variable on the flag address.
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