Searching \ for '[PIC] - delay time problem(details added)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/time.htm?key=delay
Search entire site for: '- delay time problem(details added)'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] - delay time problem(details added)'
2011\06\18@035654 by geetansh arora

picon face
sorry i missed some details which might be important in solving this
problem.

I started with my first project but it didn't worked so i decided to go back
and blink leds,now the problem is when the delay between on off  was set
10ms the leds took 2.3sec(used a stopwatch n delay was approx. 2.3sec).
At first delay was set to 500ms but it took too much time to blink so delay
was set to 10ms.
CCS compiler demo version was used for compiling , 4MHz crystal oscillator
was used with 22pF capacitors and configuration bits 2F09 were entered in
PICKIT 2 v2.61 (not used in the code)

#include <16F877A.h>
#use delay(clock=4000000)
void main()
{
while(1)
{
output_D(255);
delay_ms(10);
output_D(0);
delay_ms(10);
}
}
please solve my problem guys.
thank you and sorry again for missing the details in previous post

2011\06\18@040716 by RussellMc

face picon face
> when the delay between on off  was set
> 10ms the leds took 2.3sec

2300 mS / 10 mS ~~~= 256

Delay MAY be out by a factor of 256, indicating that there is possibly a
prescaler in the clock that is not being accounted for.


                  Russel

2011\06\18@041141 by Veronica Merryfield

picon face
My guess is the clock is running at 32768Hz so everything is 122x slower than you think.

On 2011-06-18, at 12:56 AM, geetansh arora wrote:

{Quote hidden}

> -

2011\06\18@050345 by geetansh

picon face

how can i remove that prescaler then?



RussellMc wrote:
{Quote hidden}

> -

2011\06\18@051603 by IVP

face picon face
> 2.3sec

2.3s is the longest interval of the Watchdog timer. 18ms (actual
period) x 128 (pre-scaler in OPTION)

If you aren't needing it, do you have it disabled ?

Jo

2011\06\18@110145 by Joe Wronski

flavicon
face
 First, you prove that a prescaler is there (which I doubt).  You can do that by getting CCS to output a lst file, and you analyze what the compiler is doing before it gets to main().  You check to see if it is doing anything with the clock to add a prescaler.  You can also look at the disassembly to sanity check the values passed to the delay() function (it's probably a macro).
My guess is that a floating input pin RBx is causing interrupts and the isr is using up most of the processors time.  So, you check to see if the compiler put any isr vectors in there.  And you prevent portb interrupt on change on floating inputs by enabling portb pullups.
If you have debugger capabilities, it is easier to do some of these things by setting breakpoints, examining register contents, and single stepping.   Inserting dummy code in main() before the loop will let you set a breakpoint.  The dummy code should do something that doesn't get optimized out, like "unsigned char n; n = PORTB;"
If it's the watchdog timer, or something else causing a reset, you will find that if you set a breakpoint before the loop, the breakpoint will be hit more than once.  You can also set a breakpoint at the isr vector to see if it is a robue interrupt.

Joe W


On 6/18/2011 5:03 AM, geetansh wrote:
{Quote hidden}

>> --

2011\06\18@113012 by Kerry Wentworth

flavicon
face
My somewhat outdated CCS compiler does delays using NOPs in a loop, not a timer.  Also, the 877 has no internal oscillators.

Since you don't enable interrupts (and they default to 'off'), it seems to me it can only be 2 things:

1)  The debugger is using a LOT of time (seems unlikely)

2)  The oscillator is not really running at 4MHz.

Try running without the debugger (config=0F09), because that's easy.
If that doesn't do it, write your own delay

ms_delay(int d)  // Only works with 4MHz clock!!!
{
   for(i=0;i<d;i++)
   {
      for(j=0;j<100;j++)
      {
         #asm
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
            nop
      #endasm
      }
   }
}

If that gives you the correct delay, the problem is the delay_ms() routine, otherwise, it is the clock frequency.

Kerry

geetansh arora wrote:
{Quote hidden}

>

2011\06\18@114815 by geetansh

picon face

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   019
0003:  NOP
..................... // Source code file: ENDLESS.C ..................... // Program function: Outputs variable count ..................... #include <16F877A.h> ..................... //////// Standard Header file for the PIC16F877A device
//////////////// ..................... #device PIC16F877A ..................... #list .....................  ..................... #use delay(clock=4000000) 0004:  MOVLW  21
0005:  MOVWF  04
0006:  BCF    03.7
0007:  MOVF   00,W
0008:  BTFSC  03.2
0009:  GOTO   018
000A:  MOVLW  01
000B:  MOVWF  78
000C:  CLRF   77
000D:  DECFSZ 77,F
000E:  GOTO   00D
000F:  DECFSZ 78,F
0010:  GOTO   00C
0011:  MOVLW  4A
0012:  MOVWF  77
0013:  DECFSZ 77,F
0014:  GOTO   013
0015:  GOTO   016
0016:  DECFSZ 00,F
0017:  GOTO   00A
0018:  RETURN
..................... void main() .....................  ..................... { 0019:  CLRF   04
001A:  BCF    03.7
001B:  MOVLW  1F
001C:  ANDWF  03,F
001D:  BSF    03.5
001E:  BSF    1F.0
001F:  BSF    1F.1
0020:  BSF    1F.2
0021:  BCF    1F.3
0022:  MOVLW  07
0023:  MOVWF  1C
..................... while(1) ..................... { ..................... output_D(255); 0024:  CLRF   08
0025:  MOVLW  FF
0026:  BCF    03.5
0027:  MOVWF  08
..................... delay_ms(100); 0028:  MOVLW  64
0029:  MOVWF  21
002A:  CALL   004
..................... output_D(0); 002B:  BSF    03.5
002C:  CLRF   08
002D:  BCF    03.5
002E:  CLRF   08
..................... delay_ms(100); 002F:  MOVLW  64
0030:  MOVWF  21
0031:  CALL   004
..................... } 0032:  BSF    03.5
0033:  GOTO   024
..................... } 0034:  SLEEP

Configuration Fuses:
  Word  1: 3F73   RC NOWDT PUT BROWNOUT NOLVP NOCPD NOWRT NODEBUG NOPROTECT


this is d .lst file and no isr is here. so what i should do now?
i think there might be a problem in crystal oscillator,so if i use logic
analyzer of pickit 2 to know the frequency then problem will become much
clear.


Joe Wronski wrote:
{Quote hidden}

>>> --

2011\06\18@115654 by geetansh

picon face

here delay is 100ms and here also it took around 22seconds while on.

geetansh wrote:
{Quote hidden}

2011\06\18@160047 by Sergey Dryga

flavicon
face
geetansh <geetansh19cool <at> gmail.com> writes:


>
> Configuration Fuses:
>    Word  1: 3F73   RC NOWDT PUT BROWNOUT NOLVP NOCPD NOWRT NODEBUG NOPROTECT
>
Looks like the problem is in configuration fuses: You have crystal osc, but
fuses are for RC oscillator.  So, the PIC has random frequency due to parasitic
capacitance, but not using the crystal.

Change config to XT and see how it goes.

Good luck, Sergey Dryga
http://beaglerobotics.com

2011\06\19@042656 by geetansh

picon face

hey kerry i used your code and found some weird results
here i used both (ur code for delay and delay_ms(10)) n the result was 10ms
delay loop gave a delay of approx. 6 seconds while delay_ms gave a delay of
2 seconds and after that i changed the clock freq in code to 20MHz(using
same 4MHz crystal) and here both delays gave a delay of 10seconds.
i think the crystal oscillator is definitely not giving 4MHz but why delay
loop and delay function are not giving same results?

code used #include <16F877A.h>
#use delay(clock=20000000)
void main()

{
int16 i,j;
while(1)
{
output_D(255);
  for(i=0;i<10;i++)                                //gave a delay 6sec
  {
     for(j=0;j<100;j++)                             {
        #asm
           nop
           nop
           nop
           nop
           nop
           nop
           nop
           nop
           nop
           nop
     #endasm
     }
};
output_D(0);
delay_ms(10);                 // gave a delay of 2sec.
}
}



Kerry Wentworth wrote:
{Quote hidden}

> -

2011\06\19@082319 by Kerry Wentworth

flavicon
face
The code I gave you is very crude.  It uses a loop that executes 10 NOPs 100 times to delay 1000 instruction cycles, but there are a lot of cycles besides the NOPs that get executed, incrementing variables and checking results, etc.  It wasn't intended to be accurate, just a way to see if the clock was even close.

Try setting the configuration to HS or XT, with debugger off and see if that helps.  If not, you may have a bad crystal.

Kerry


geetansh wrote:
{Quote hidden}

>>>

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...