View previous topic :: View next topic |
Author |
Message |
SpoonBilly
Joined: 25 May 2010 Posts: 16
|
Clock is 4 times faster |
Posted: Tue Jul 10, 2012 1:41 am |
|
|
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: 19546
|
|
Posted: Tue Jul 10, 2012 2:01 am |
|
|
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
|
|
Posted: Tue Jul 10, 2012 5:47 am |
|
|
and I can't use delay_us(). Is this a related issue? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Jul 10, 2012 5:38 pm |
|
|
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
|
|
Posted: Wed Jul 11, 2012 3:31 am |
|
|
I can live with the faster clock, but what can I do to replace delay_us()? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Wed Jul 11, 2012 4:10 am |
|
|
Depends what delays you want.
I must admit, I can't find a single one of my programs, that uses 'delay_us'....
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
|
|
Posted: Wed Jul 11, 2012 7:07 am |
|
|
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
|
Re: Clock is 4 times faster |
Posted: Fri Oct 05, 2012 1:50 am |
|
|
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... |
|
|
|