View previous topic :: View next topic |
Author |
Message |
joseph
Joined: 14 Jun 2010 Posts: 16
|
PLL and Pic12LF1822 |
Posted: Wed Dec 07, 2011 10:00 am |
|
|
Hi,
I trying to make run my pic to 8 Mhz..... just blinking a led..
Code: |
#include <12LF1822.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES MCLR //Master Clear pin enabled
#use delay (clock=8000000)
//----------------------------------------------------------------
void main()
{
setup_oscillator(OSC_8MHZ);
for(;;)
{
output_high(pin_a2);
delay_us(10);
output_low(pin_a2);
delay_us(10);
}
}
//----------------------------------------------------------------
|
When a plug the oscilloscope on pin_a2..... the pulse is not 10us.... but 12us.....
Do you have an idea ???
thanks in advance. |
|
|
joseph
Joined: 14 Jun 2010 Posts: 16
|
next.... |
Posted: Wed Dec 07, 2011 10:19 am |
|
|
If wrote
Code: |
for(;;)
{
output_high(pin_a2);
delay_ms(10);
output_low(pin_a2);
delay_ms(10);
}
|
.... need 10ms, I have 8us...... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 07, 2011 1:48 pm |
|
|
Post your CCS compiler version. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Dec 07, 2011 3:44 pm |
|
|
It is not going to be 10uSec.
The instruction 'output_high', or output_low, itself takes four instructions to execute (so 2uSec), while the jump needed for the loop, takes three instructions to execute (one bank switch, and two for the jump itself). So you should see a high pulse of 12uSec, and a low of 13.5uSec.
All things take time....
Best Wishes |
|
|
joseph
Joined: 14 Jun 2010 Posts: 16
|
|
Posted: Thu Dec 08, 2011 3:24 am |
|
|
my ccs version is 4.114
A problem with this version ? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Dec 08, 2011 3:59 am |
|
|
All software times are approximate. As the others have pointed out, all code takes time to execute. So you want reasonably precise timing you either have to count cycles precisely and turn off interrupts, or use hardware. The timers/CCPs/PWMs are the tools for this.
In practise however its rare for any timed pulse to need to be a precise time, no more, no less. Most hardware data sheets specify maximum and minimum times for critical pulses, so pulses should nto be less than 5us, or something else no longer than 100us, but these are limits; rarely are they requirements for precise times.
There are occasions when the timing is the information, such as driving servos and applications such as dimmers and motor drives. For these you should use PWMs and timers and other hardware that generates accurate and easily controlled timing, and control these by firmware. If you are intending to do a software only approach for these sorts of applications then please think again.
In general the main use of delay_xs() routines should be for short pauses (a hundred us or so at most) and timers, interrupts and flags and hardware, on or off PIC, for anything longer.
Folks have reported some problems with delay_xs() routines on some PICs with some compiler issues. If I remember correctly delay_ms() is the most commonly affected. You may have run up against that problem.
RF Developer |
|
|
joseph
Joined: 14 Jun 2010 Posts: 16
|
|
Posted: Thu Dec 08, 2011 4:56 am |
|
|
The more recent version do best result...
1.114 to 1.120..... and no problem ! |
|
|
|