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

Extra clock cycle

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



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

Extra clock cycle
PostPosted: Fri Dec 22, 2017 9:56 am     Reply with quote

I am using a USB Master dev kit (18F67J10) to generate a fast clock. The clock must run for 68 microseconds. Here is the code:
Code:
....................   // set up timer 1 to interrupt in 68 us. At 40 Mhz, timer1 tick is .8 us, so it takes 85 ticks for 68 us.
....................   // T1 is a 16 bit timer so the preload value is 65536 - 85 = 65451
....................   set_timer1 (65451);
00E10:  SETF   FCF
00E12:  MOVLW  AB
00E14:  MOVWF  FCE
....................   gb68us = 0;
00E16:  MOVLB  3
00E18:  CLRF   xA2
....................   do {
....................      output_low (PIN_F4);
00E1A:  BCF    F97.4
00E1C:  BCF    F8E.4
....................      output_high (PIN_F4);
00E1E:  BCF    F97.4
00E20:  BSF    F8E.4
....................   }
....................   while (gb68us == 0);
00E22:  MOVF   xA2,F
00E24:  BZ    0E1A
....................   disable_interrupts (int_timer1);
00E26:  BCF    F9D.0

The global variable gb68us is an int8 and is set to one by the timer1 interrupt handler.

It works very well except for one thing. After it is done, a single extra clock pulse is generated, 11 microseconds after the last normal cycle. Or it may be that the last pulse is delayed for 11 us. I set a breakpoint on the disable_interrupts line and the extra pulse is still generated (or delayed). I cannot figure out why.

Can anyone give me a clue as to what could cause this?
Thanks, Russ
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Fri Dec 22, 2017 12:16 pm     Reply with quote

That's about the time it'd take to get into and out of the interrupt handler. Probably the delay....
Leave the interrupt disabled.
Code:

    disable_interrupts(INT_TIMER1);
    clear_interrupts(INT_TIMER1);
    do
    {
        output_low (PIN_F4);
        output_high (PIN_F4);
    }
    while (!interrupt_active(INT_TIMER1));


Interrupts are _slow_. They give you a response, but not for a significant time. Testing the flag tells you when it triggers
A disabled interrupt can still set, it just can't call a handler.
russk2txb



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

PostPosted: Fri Dec 22, 2017 4:33 pm     Reply with quote

Thanks Ttelmah. You always have great answers. That worked just right. I am really not sure exactly how the interrupt delay got in the way of processing that last pulse on time, but it is obvious that it did. I had already tried not turning off the interrupt and it made no difference. But success is what is important here.

Thanks again, Russ
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