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

interrupts time doubt

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



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

interrupts time doubt
PostPosted: Sun Feb 28, 2010 3:29 pm     Reply with quote

Hi, I have a doubt about the interrupts.

My question is:

I have a done a program that reads an encoder by the portbB, actually, I changed the program that Ttelmah left, then I put a timer and I let the software count how many encoder counts can we get in 10 interrupts, then I said, ok, the speed of my motor is XXX counts per interrupt.

But where is my problem, I did that with a clock of 20MHZ, now I using a clock of 48mhz because I have changed the whole software into a RS232toUSB connection, and the counts per interrupts are the same, BUT not the counts per second, because this is how I set my timer:

USB
Code:

setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT); // (48000000/(4*256*256)) = ~183.11


RS232
Code:

setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);  // (20000000/(4*256*256)) = ~76.294


I was expecting small interrupt time, but then I thought that the interrupts has a length of what is inside, and inside is the encoder routine.

Thanks for any help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 01, 2010 12:06 am     Reply with quote

I don't understand your explanation completely. I think you have stated this:

1. You have changed the oscillator on your PIC from 20 MHz to 48 MHz.

2. With the 20 MHz oscillator, the RTCC interrupts at a rate of 76 Hz.
But with the 48 MHz oscillator, it interrupts at a rate of 183 Hz.

3. Inside the #int_rtcc interrupt routine, you read a motor encoder
of some type (the type of encoder is not stated).

4. You referred to a previous post by Ttelmah. Can you provide a link
to this post ?

5. You state that the "counts per second" is not the same. Does this
refer to the "counts" from the motor encoder, or do you mean the
RTCC interrupt rate ?

6. You said you were expecting a small interrupt time. Are you referring
to the overhead (execution time) of the CCS interrupt handler ?
This handler has to "save the state of the machine" upon getting the
interrupt, and restore it upon exit. This takes time. It will take less time
with a 48 MHz oscillator.

Can you state your overall problem ? Is your problem that with a
48 MHz oscillator, the motor speed is not determined correctly now ?

Also, always post your PIC, and preferably, also post your compiler version.
jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Mon Mar 01, 2010 12:29 pm     Reply with quote

Thanks PCM, you were right in all your points.

I could not find again the post by Ttelmah, but this is his routine:
Code:

void myint(void) {
   new=input_b();
   value=new^old;
   if (value & 0x10) {
      if (new & 0x10) {
         if (new & 0x20) --position;
         else ++position;
      }
      else {
         if (new & 0x20) ++position;
         else --position;
      }
   }
   else {
      if (new & 0x20) {
         if (new & 0x10) ++position;
         else --position;
      }
      else {
         if (new & 0x10) --position;
         else ++position;
      }
   }
   old=new;
   bchanged=0;
}

I am using PIC18F4550 and a compiler version 3.245.

And well, I believe your gave me the answers in your point 6.

I will try explain my problem again, english is not my native language, sorry for any mistake.

I have built a routine to control 1 dc servo motor implementing a PI controller with a close loop of position, someone left here a post asking for a speed close loop, so, I looked in internet about and I found this:

http://www.scribd.com/doc/17303175/Implementing-Embedded-Speed-Control-for-Brushless-DC-Motors-Part-5

I tried to do it by myself, and my problem is measure the speed of the motor, because as I understand an interrupts takes of what it has inside of, so, with the same duty_cycle but different clock the encoder counts per interrupts should be the same, notwithstanding if I want the encoder counts per second is different because the total amount of interrupts by second are different.

This is my doubt, but you said that each interrupts It will take less time with a 48 MHz oscillator, now I going to make some measurements.

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