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

Communication between two PICs
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Mon May 28, 2007 12:49 pm     Reply with quote

I have only one question left regarding this topic. One thing which I don't understand. When I originally tried to run the 16F627A at 20Mhz using:

#use delay(clock=20000000)

then the CPU was actually running slower than when I changed to 4Mhz:

#use delay(clock=4000000)

The way I could betect this was that my pulses for servo control:

Output_high(servo);
Delay_us(pulse);
Output_low(servo);
Delay_us(2000-pulse);

on the scope showed that the pulses occur every 100ms.

What is the explanation of this?

Thank you, Oxy.
Humberto



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

View user's profile Send private message

PostPosted: Mon May 28, 2007 12:57 pm     Reply with quote

To be sure regarding timing discrepancies or oddities, the best is to assign a know value
to the built-in delay_xs() functions. Once the expected delays are in accordance
with the used clock frequency, you can start playing with variables parameters.
In your posted example, we don´t know the previous value of the variable "pulse",
hence we can´t know if 100 ms is right or wrong.


Humberto
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Mon May 28, 2007 1:17 pm     Reply with quote

I am sorry about that, these were posted previously in this thread, I guess I should have specified it again:
Here is the whole sequence:
Code:

  Pulse = 1500;
      While(true) {

            Pause = 20000 - Pulse;           //Calculate interval lenght
            Output_high(Servo);              //Set port on high
            delay_us(Pulse);                 //Wait for the duration of the pulse
            Output_low(Servo);               //Set port low
            delay_us(Pause);
      }


In this case with the #use delay(clock=20000000) the scope showed that the pulses occur every 100ms. Once I changed it to #use delay(clock=4000000) the pulses were at the correct timing at evey 20ms.
Humberto



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

View user's profile Send private message

PostPosted: Mon May 28, 2007 1:56 pm     Reply with quote

Quote:

What is the explanation of this?

You have the answer in this equity:
20000000/4000000 = 100/20

I used the values that you posted.

The compiler can´t know the real frequency, it doesn´t matter the crystal frequency used,
instead it assume the value assigned to clock=xxxxxxxx for all the calculations were time is involved.

Humberto


Last edited by Humberto on Mon May 28, 2007 2:06 pm; edited 1 time in total
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Mon May 28, 2007 2:06 pm     Reply with quote

Ok,

Now I understand. Thank you.You must have edited your post while I was writing mine.

Oxy.
Humberto



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

View user's profile Send private message

PostPosted: Mon May 28, 2007 2:18 pm     Reply with quote

Quote:

However, the delay_ms(20) should be the same lenght for the 20Mhz clock as for the 4Mhz clock - since I am specifying ms - miliseconds - not caring how fast the clock runs at. If it is not why is it not?

When you specify clock=x, you are giving to the compiler a time unit.
This time unit is used further in all the calculus where the time is involved.
As I said, there is no way for the compiler to know the hardware clock speed.


Humberto
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Mon May 28, 2007 2:23 pm     Reply with quote

Thank you again, I actually deleted that post, because I understood that by your previously edited post.

Sorry for the confusion.
Ttelmah
Guest







PostPosted: Tue May 29, 2007 2:42 am     Reply with quote

One problem here, is with the CCS documentation often being relatively 'unclear', and also the way that their functions do different things on different chips.
So (in this case), '#use delay', on chips with programmable internal oscillators, 'doubles up', with the 'setup_oscillator' function, and will automatically program the oscillator rate, but on chips without this ability, it only provides 'data' about what oscillator is connected. This 'dual' nature, can make the behaviour quite 'non intuitive' at times. Smile

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
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