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

same code but different pulse width

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



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

same code but different pulse width
PostPosted: Mon Sep 27, 2004 2:32 am     Reply with quote

Hi...

I have used 16F877 in our projectusing 20MHz Oscillator.
And now we have only one interrupt on Timer1.

I have set the Timer1 to overflow every 0.2mSec. If I run
this code saperately, it is giving correct pulse width and
Duty Cycle. But if I use it in our project which has long
code. It is giving different pulse width. And all the pulses
are not of the same pulse width or Duty Cycle. The code inside
the interrupt is simple.

If I put the cursor at the first line of ISR and "Run To Cursor", everytime
it is giving different time and instruction cycle.

I don't know why this is happen. But think it is due to long
code. As my RAM and ROM are about to fill and I have long
code in side the main(),while loop.
Can this be reason for incorrect Pulse Width..??
I can't understand, why interrupt is not happen at proper time
when it is having long code. while the same code is giving
correct pulse width in one simple program.

If Timer is incremented every instruction cycle, why is it not
same for same oscillator and circuit.

Thanks...Any help appriciated...

Regards
Prashant
Ttelmah
Guest







Re: same code but different pulse width
PostPosted: Mon Sep 27, 2004 3:42 am     Reply with quote

Prashant Patel wrote:
Hi...

I have used 16F877 in our projectusing 20MHz Oscillator.
And now we have only one interrupt on Timer1.

I have set the Timer1 to overflow every 0.2mSec. If I run
this code saperately, it is giving correct pulse width and
Duty Cycle. But if I use it in our project which has long
code. It is giving different pulse width. And all the pulses
are not of the same pulse width or Duty Cycle. The code inside
the interrupt is simple.

If I put the cursor at the first line of ISR and "Run To Cursor", everytime
it is giving different time and instruction cycle.

I don't know why this is happen. But think it is due to long
code. As my RAM and ROM are about to fill and I have long
code in side the main(),while loop.
Can this be reason for incorrect Pulse Width..??
I can't understand, why interrupt is not happen at proper time
when it is having long code. while the same code is giving
correct pulse width in one simple program.

If Timer is incremented every instruction cycle, why is it not
same for same oscillator and circuit.

Thanks...Any help appriciated...

Regards
Prashant

Look at anything that is used inside both the ISR, and the main code. Because the processor does not have a 'stack' to hold variables (as opposed to the 'call' stack), if a routine is used inside the ISR, and is also used inside the main routine, then interrupts have to be disabled to the routine outside the ISR. This will then delay the point when you arrive inside the ISR, and give erratic timings. Some 'simple' things can trigger this (for instance a 'switch' statement that does not have a 'default'), since for this, a 'table' based jump is used, and the interrupts will be disabled for any similar jumps in the main code. Similarly certain array accesses will trigger this too. Obviously, if you manually disable interrupts at any point, the same behaviour will also result. Some code will also result in interrupts being disabled (look at program EEPROM write cycles).

Best Wishes
Prashant Patel



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

Possible reason which can stop ISR to be executed
PostPosted: Mon Sep 27, 2004 3:10 pm     Reply with quote

Hi...

I have very simple code inside ISR to generate the
pulses of certain duty cycle. And I have only one
ISR.
Along with this, I am sending my code which is generating
correct pulse width and duty cycle. But if I use the same
code with all other code inside the main loop. Then it
is generating some pulses with double the width. Which
seems like missing at some points to execute the ISR.

Is there anything that can prevent the call of ISR..??
So that I can know that these code can prevent the ISR
to be executed. So need to change of do something else
to that code to stop to prevent ISR to be executed. Because
ISR must be executed when ever Timer1 is overflowed.

---------------------------------------------------------
Code Details:
-------------
int16 PULSE_TIME= 65436; // To generate the pulses of some mSec.
signed int8 count;
signed int8 DCOnDuty=30;

#INT_TIMER1
void timer1_isr() {

count++;

if(count<=DCOnDuty)
output_high(PIN_D0);
else
output_low(PIN_D0);

set_timer1(PULSE_TIME); //Set the timer to overflow every xx mSec

if(count>=100)
count=0;

}//timer1_isr
---------------------------------------------------------

Thanks...

Regards
Prashant
J_Purbrick



Joined: 16 Sep 2003
Posts: 9

View user's profile Send private message

PostPosted: Mon Sep 27, 2004 4:12 pm     Reply with quote

I'm not sure I'd have thought of what Ttelmah said, but it sounds very plausible. The compiler will suppress interrupts under some conditions and as I recall, there is no warning (I would call that a serious bug, in the microcontroller world).

Simply the length of your main() routine or the functions that it calls can't be having any effect. It's something else.
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