Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
the blink time of a led is different in boot mode and in icsp mode
13-02-2017, 05:07 PM,
#1
the blink time of a led is different in boot mode and in icsp mode
Hello

i'm a new user of pinguino v12.0.0 beta 1 under win 7 but a old user of pcs of any type.

I work with a card based on 18f4550 with xtal 20MHz.

I try the blink code for test the card, so i program the card with the bootloader under uns and the blink of the led seems to be ok (approx 1s).

I want to program the board with the iscp pickit3. So i compile it with the icsp function.

And when i put it on the pic, the blink is approx 0.5s.

I try to find the answer in the forum. I saw something about millis but it seems not to be my problem.

I define, for the iscp mode, cristal at 20MHz.

So, if somebody know a solution, i take it.

Thanks a lot.

Fred.
Reply
16-02-2017, 02:19 PM,
#2
RE: the blink time of a led is different in boot mode and in icsp mode
Hi Fred,
You said you chose the ICSP mode and set the crystal at 20MHz.

Does it mean your program starts with #define CRYSTAL 20000000 (which it should) ?
Then the issue comes from main.c (in Pinguino/v12/source)
Can you please replace :

#ifdef CRYSTAL
unsigned long _cpu_clock_ = CRYSTAL;
#else
unsigned long _cpu_clock_ = 48000000;
#endif

with :
unsigned long _cpu_clock_ = 48000000;

Is it better ?
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
17-02-2017, 10:53 PM,
#3
RE: the blink time of a led is different in boot mode and in icsp mode
Hi Regis,

Thanks a lot for answer.

With your modification the programs compiled for bootloader and icsp are blinking exactly at the same speed.

The first problem is corrected.

But now, when i put a delay of 1000ms, the real time generated is 400 ms, so 5 /2 less.

Is it something related to divide by 5 usb config and cpudiv divide by 2?

It was Nice to read from you.

Thanks.

Fred
Reply
21-02-2017, 12:47 PM,
#4
RE: the blink time of a led is different in boot mode and in icsp mode
Hi Regis,

in the next question, I've a problem with a simulator, i don't know why.

But in real life, it works perfectly now.

In the two mode, i obtain the same time.

I continu testing.

Thanks for your reactivity.

Fred
Reply
08-03-2017, 08:09 PM,
#5
RE: the blink time of a led is different in boot mode and in icsp mode
Hi Fred,
Sorry I was on holidays ...
Do you mean the 1000ms delay is in fact 400ms ?
Here is a program I use to calibrate the delay routine :


void setup()
{
    pinMode(USERLED, OUTPUT);
    Serial.begin(9600);
}

void loop()
{
    u16 t;                        // time in ms
    u32 start, delta;
    
    //Serial.printf("CPU = %ld Hz\r\n", _cpu_clock_);

    for (t=100; t<=5000; t=t+100)
    {
        // Test Delay ms
        start = millis();
        delay(t);
        delta  = millis() - start;
        toggle(USERLED);
        Serial.printf("delay(%d) = %d ms\r\n", t, delta);
    }
}
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)