delay argument too long : showing error

Discussion in 'Embedded Systems and Microcontrollers' started by ect_09, Oct 22, 2014.

  1. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    Code (Text):
    1. #include<htc.h>
    2.  
    3. __CONFIG(1, OSCSDIS & HSPLL);
    4. __CONFIG(2, BORDIS & PWRTDIS & WDTDIS);
    5. __CONFIG(3, CCP2RC1);
    6. __CONFIG(4, LVPEN & STVREN);
    7. __CONFIG(5, UNPROTECT);
    8. __CONFIG(6, WRTEN);
    9. __CONFIG(7, TRU);
    10.  
    11. #define _XTAL_FREQ 4000000
    12.  
    13. void sevenseg(char ch);
    14.  
    15. void main()
    16. {
    17.    char ch;
    18.    TRISB=0;
    19.    PORTB=0x00;
    20.  
    21.   while (1)
    22.   {
    23.      ch = (++ch) % 10;
    24.      sevenseg(ch);
    25.      __delay_ms(1000);
    26.    
    27.    
    28.   }
    29. }
    30.  
    31. void sevenseg(char ch)
    32. {
    33.   switch(ch)
    34. {
    35.    case 0: PORTB=0x3F; break;
    36.    case 1: PORTB=0x06; break;
    37.    case 2: PORTB=0x5B; break;
    38.    case 3: PORTB=0x4F; break;
    39.    case 4: PORTB=0x66; break;
    40.    case 5: PORTB=0x6D; break;
    41.    case 6: PORTB=0x7D; break;
    42.    case 7: PORTB=0x07; break;
    43.    case 8: PORTB=0x7F; break;
    44.    case 9 : PORTB=0x6F; break;
    45.    default: PORTB=0x3F;
    46. }
    47. }
    __delay_ms(1000);
    error showing that this delay argument is too long :)
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    From the Hi-Tech manual:
    __delay_ms.png
     
    ect_09 likes this.
  3. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    i also define _XTAL_FREQ
    but also getting error that delay argument is too large.. :)
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    If you are getting an error your delay argument is too large then you should suspect the delay argument is too large.

    So make it smaller. Try two delays of 500, or 4 delays of 250 (I suspect the latter will work).
     
    tshuck likes this.
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    There is a whole other part to the sentence you are referring to. It is there for a reason.

    Let's look at it, from the Hi-Tech manual, __delay_ms() wraps around delay (), which delays for a number of cycles. At 4MHz, one cycle is 1/(4Mhz/4), or, 1us. In order to get to a thousand milliseconds, it must be able to count to one million. 1000000 requires log(1000000)/log (2) = 20 bits. I'd be surprised if it would permit anything over 16 bits, though the manual doesn't say what the magic number is.

    User a smaller requested delay as Ernie suggested, loop it as necessary.
     
    adam555 likes this.
  6. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    i tried this way with 250 250 250 250 but didnt get 1 sec delay
     
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    What did you get? Which PIC is this?
     
  8. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    its PIC18f452 .
    using Hi-Tech compiler
    with MPLAB
     
  9. adam555

    Active Member

    Aug 17, 2013
    858
    39
    Not all PICs have an internal clock running at 4 MHz as default. Have you tried changing the _XTAL_FREQ to 10 MHz? This could be the default internal frequency.
     
    tshuck likes this.
  10. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    As Adam intimated, there is no internal oscillator on this chip. What value is your external oscillator? Is it 4 MHz?

    I find it troubling that you haven't set the oscillator type in your configuration bits - assuming OSCDIS disables clock switching.

    The default is an RC oscillator, is that what you're using?
    Screenshot_2014-10-24-07-09-33~2.jpg

    You must learn to read the manual...
     
Loading...