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

Clock is 4 times faster

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



Joined: 25 May 2010
Posts: 16

View user's profile Send private message

Clock is 4 times faster
PostPosted: Tue Jul 10, 2012 1:41 am     Reply with quote

I am using PCWHD version 4.134 and MPLAB ICD3. What puzzles me is that the clock seems to work 4 times faster. Let say if I am using baudrate 9600, I can only receive what I want at the computer at baudrate 38400 (4 x 9600). The following code should work at 23.5Hz, but it works at 94Hz (as if the crystal is 80MHz, 4 x 20MHz). What went wrong? help please~

Code:

#include <16F1823.h>
#fuses   HS,NOWDT,NOPROTECT,NOLVP
#use     delay(clock=20000000)
#use     rs232(baud=9600, xmit=PIN_A0, invert)

unsigned int16 i ;

#int_TIMER1
void TIMER1_isr()
{
   set_timer1(12500) ;
   
   i++ ;
   
   printf("%lu\r\n", i) ; 
}
   
void main()
{
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4) ;
   enable_interrupts(INT_TIMER1)          ;
   enable_interrupts(GLOBAL)              ;
   
   while(TRUE) ;
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19396

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 2:01 am     Reply with quote

This is down to a new chip architecture, and will probably take CCS a while to catch up with....
If (for example), you look at the clock sources for the timer1 module (fig 21-1), you will see that the module can be clocked internally from 'Fosc', or from 'Fosc/4'. This differs from all the traditional PIC's, where the peripherals always run from Fosc/4. Similarly with the UART, the master clock feeding into the BRG (Figure 26-1), is Fosc, rather than Fosc/4.....
The CPU itself still performs instructions at the Fosc/4 rate, but all the peripheral stuff will clock at 4* the expected rate.....

Best Wishes
SpoonBilly



Joined: 25 May 2010
Posts: 16

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 5:47 am     Reply with quote

and I can't use delay_us(). Is this a related issue?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jul 10, 2012 5:38 pm     Reply with quote

From hard experience I can attest that extended compiler,
high level function support is still quite weak for 16F15xx, 16f19xx and 16f18xx parts.

Be prepared to do some patching as you go.....

The issues you list can be solved with a bit of creative programming.
an alternative is to just use an older part if you can.
SpoonBilly



Joined: 25 May 2010
Posts: 16

View user's profile Send private message

PostPosted: Wed Jul 11, 2012 3:31 am     Reply with quote

I can live with the faster clock, but what can I do to replace delay_us()?
Ttelmah



Joined: 11 Mar 2010
Posts: 19396

View user's profile Send private message

PostPosted: Wed Jul 11, 2012 4:10 am     Reply with quote

Depends what delays you want.

I must admit, I can't find a single one of my programs, that uses 'delay_us'....
Smile
For short delays, use 'delay_cycles'. For longer delays, have a timer 'tick' interrupt, and run a countdown clock in this.
The delay problem, applies to quite a few chips, and if I remember correctly, does work OK, with shorter delays.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Jul 11, 2012 7:07 am     Reply with quote

for your two cited issues
Code:

#use  ...  baud=2400 for 9600 actual

how does    delay_us(desired_us*4);

work ?

nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

Re: Clock is 4 times faster
PostPosted: Fri Oct 05, 2012 1:50 am     Reply with quote

Code:
#FUSES PLL_SW                   //4X HW PLL disabled


Put this code in Header file and all timers and function works in normal mode
Best regards...
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