PIC18F4550 - Delay10KTCYx

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

PIC18F4550 - Delay10KTCYx

Postby w_schwanen » Sat Jul 05, 2008 5:31 am

Hello everybody,

I try to make a delay of 1min using the Delay10KTCYx fonction.
I use a PIC18F4550 20MHz (The 18F4550 is running at 20MHz oscillator frequency, but the internal frequency is 48MHz). But I have more than 1min, about 1min20. I don't understand why! Maybe it's because of my configuration bits but it seems correct. So does somebody could help me?

Thanks a lot!

code:

Code: Select all
#include <p18f4550.h>
#include<stdio.h>
#include <delays.h>



void main (void)
{
int i;

printf("start\n");

for (i=0;i<60;i++)
{
Delay10KTCYx(250);
Delay10KTCYx(250);
}


printf("end\n");

while(1);
}
w_schwanen
 
Posts: 6
Joined: Mon Jun 02, 2008 2:06 pm

Postby w_schwanen » Sat Jul 05, 2008 5:53 am

w_schwanen
 
Posts: 6
Joined: Mon Jun 02, 2008 2:06 pm

Postby jasonharper » Sat Jul 05, 2008 6:13 am

The configuration bits you posted should give a clock rate of 48 MHz, which is 12 million instruction cycles per second. Your code should be taking about 25 seconds to execute. The fact that it's taking about 3 times longer than that indicates that the actual clock rate is closer to 16 MHz, which is what you'd get if the clock postscaler was set to /6 instead of /2. I can only conclude that you're not successfully programming the config bits into the PIC; what sort of programming hardware are you using?
jasonharper
 
Posts: 845
Joined: Wed Mar 02, 2005 12:14 pm
Location: Oklahoma

Postby w_schwanen » Sat Jul 05, 2008 7:28 am

First thank the answer :)
I made a mistake in the code. I think this code is right according a clock of 48Mhz and if I want 1min but it's longer than 1min...
My programming hardware is MPLAB and I use the ICD2. I manage to do many thing with a PIC18F4550 USB Development Board, like DAC,ADC...and now I just want a delay to write in the EEPROM every minute.
Actually I didn't try the delay on my hardware, I tried with the simulator "MPLAB SIM" maybe it's where I'm wrong because when I change the clock in the congiguration bits, there is no change for delay. So I'm going to try on my hardware. Could it be the origin of the error?? Thank a lot
Code: Select all
#include <p18f4550.h>
#include<stdio.h>
#include <delays.h>
void main (void)
{
int i,j;

for (i=0;i<60;i++)
{
printf("Start\n");
Delay10KTCYx (240);
Delay10KTCYx (240);
Delay10KTCYx (240);
Delay10KTCYx (240);
Delay10KTCYx (240);
}
printf("end");
while(1);

}
:)
w_schwanen
 
Posts: 6
Joined: Mon Jun 02, 2008 2:06 pm

Postby w_schwanen » Sat Jul 05, 2008 9:01 am

t's working now. I programed the hardware by turning on a led at time 0 and turning off after the delay. I had 1min.
So thanks Jasonharper.

for information: code for the LED

Code: Select all

#include <p18f4550.h>
#include <delays.h>

void main (void)
{
int i,j;
DDRAbits.RA2=0;   /*RA2 input*/
PORTAbits.RA2=0;

for (i=0;i<60;i++)
{
PORTAbits.RA2=1;/*LED on*/
Delay10KTCYx (240);/*200ms*/
Delay10KTCYx (240);
Delay10KTCYx (240);
Delay10KTCYx (240);
Delay10KTCYx (240);
}
PORTAbits.RA2=0;/*LED off*/
while(1);

}


Configuration bits:
Configuration bits
w_schwanen
 
Posts: 6
Joined: Mon Jun 02, 2008 2:06 pm

Re: PIC18F4550 - Delay10KTCYx

Postby qAyyUm » Mon Oct 03, 2011 11:10 am

w_schwanen wrote:Hello everybody,

I try to make a delay of 1min using the Delay10KTCYx fonction.
I use a PIC18F4550 20MHz (The 18F4550 is running at 20MHz oscillator frequency, but the internal frequency is 48MHz). But I have more than 1min, about 1min20. I don't understand why! Maybe it's because of my configuration bits but it seems correct. So does somebody could help me?

Thanks a lot!

code:

Code: Select all
#include <p18f4550.h>
#include<stdio.h>
#include <delays.h>



void main (void)
{
int i;

printf("start\n");

for (i=0;i<60;i++)
{
Delay10KTCYx(250);
Delay10KTCYx(250);
}


printf("end\n");

while(1);
}




Hello... What is Delay10KTCx??
qAyyUm
 
Posts: 3
Joined: Mon Oct 03, 2011 11:07 am

Re: PIC18F4550 - Delay10KTCYx

Postby bill190 » Wed Oct 05, 2011 8:37 am

google Delay10KTCYx
bill190
 
Posts: 101
Joined: Sat May 01, 2010 8:03 am
Location: Oregon


Return to PIC Microcontrollers - Software and Hardware

Who is online

Users browsing this forum: MSNbot Media and 1 guest