This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Re: Long Integer Multiple Error

Think you.
I modified my source :

        printf("%lu * %bu = ", N, M);
        printf("%lu\n", Freq);

        Freq=25690112L;
        printf("%lu * %bu = ", Freq, 4);
        Freq*=4;
        printf("%lu\n", Freq);


It work correctly.
but the Long Integer Multiple fault also.

Run Result:
24500000 * 4 = 4294926936
25690112 * 4 = 1568

Parents
  • Long Integer Multiple Error. Target Options: MCU : C8051F120F, Use On-chip Arithmetic Accelerator.

    Source:

    #include <C8051F120.H>
    #include <stdio.h>
    
    unsigned long Freq;
    
    void DetectFreq()
    {
            unsigned long N;
            unsigned char M;
        SFRPAGE   = CONFIG_PAGE;
            M= PLL0MUL;
            switch (CLKSEL&0x03) {
                    case 00:        //Internal XTAL
                    case 03:
                                            Freq=25690112;//24.5L*1024L*1024L
                                            switch(OSCICN&0x03){
                                                    case 0x00: Freq/=8; break;
                                                    case 0x01: Freq/=4; break;
                                                    case 0x02: Freq/=2; break;
                                            }
                                            break;
    
                    case 01:        // External XTAL
                                            Freq=25L*1024L*1024L;
                                            switch (OSCXCN&0x70) {
                                                    case 0x03:
                                                    case 0x05:
                                                    case 0x07: Freq=Freq/2; break;
                                            }
                                            break;
                    case 02:        //PLL
                                            if (PLL0CN&0x04) { // External XTAL
                                                    Freq=26214400L;  //25L*1024L*1024L
                                                    N=Freq;
                                                    Freq*=PLL0MUL;
                                                    Freq/=PLL0DIV;
                                                    switch (OSCXCN&0x70) {
                                                            case 0x03:
                                                            case 0x05:
                                                            case 0x07: Freq=Freq/2; break;
                                                    }
    
                                            }
                                            else{
                                                    //Freq=25690112L;
                                                    Freq=24500000L;//25690112L;
                                                    N=Freq;
                                                    Freq*=PLL0MUL;
                                                    //FreqMul(PLL0MUL);
                                                    Freq/=PLL0DIV;
                                                    switch(OSCICN&0x03){
                                                            case 0x00: Freq/=8; break;
                                                            case 0x01: Freq/=4; break;
                                                            case 0x02: Freq/=2; break;
                                                    }
                                            }
                                            break;
            }
            SFRPAGE   = LEGACY_PAGE;
            printf("%lu * %u = ", N, M);
            printf("%lu\n", Freq);
    
            Freq=25690112L;
            printf("%lu * %u = ", Freq, 4);
            Freq*=4;
            printf("%lu\n", Freq);
    
    }
    
    void InitSerial()
    {
            SFRPAGE =LEGACY_PAGE;
        SCON0  = 0x50;                      /* SCON: mode 1, 8-bit UART, enable rcvr      */
        TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload        */
        TH1   = 221;                /* TH1:  reload value for 1200 baud @ 16MHz   */
        TR1   = 1;                  /* TR1:  timer 1 run                          */
        TI0    = 1;                  /* TI:   set TI to send first char of UART    */
    }
    
    // Peripheral specific initialization functions,
    // Called from the Init_Device() function
    void Reset_Sources_Init()
    {
        WDTCN     = 0xDE;
        WDTCN     = 0xAD;
    }
    
    void EMI_Init()
    {
        SFRPAGE   = EMI0_PAGE;
        EMI0CF    = 0x1F;
        //EMI0TC    = 0x4F;
               EMI0TC    = 0xCF;
    
    }
    
    void Port_IO_Init()
    {
        SFRPAGE   = CONFIG_PAGE;
        P4MDOUT   = 0xFF;
        P5MDOUT   = 0xFF;
        P6MDOUT   = 0xFF;
        P7MDOUT   = 0xFF;
        XBR0      = 0x07;
        XBR1      = 0x94;
        XBR2      = 0x40;
    }
    
    void Oscillator_Init()
    {
        data int i = 0;
        SFRPAGE   = CONFIG_PAGE;
        CCH0CN    &= ~0x20;
        SFRPAGE   = LEGACY_PAGE;
        FLSCL     = 0xB0;
        SFRPAGE   = CONFIG_PAGE;
        CCH0CN    |= 0x20;
        PLL0CN    |= 0x01;
        PLL0DIV   = 0x01;
        PLL0FLT   = 0x01;
        PLL0MUL   = 0x04;
        for (i = 0; i < 15; i++);  // Wait 5us for initialization
        PLL0CN    |= 0x02;
        //while ((PLL0CN & 0x10) == 0);
        CLKSEL    = 0x02;
        OSCICN    = 0x83;
    }
    
    // Initialization function for device,
    // Call Init_Device() from your main program
    void Init_Device(void)
    {
        Reset_Sources_Init();
        EMI_Init();
        Port_IO_Init();
        Oscillator_Init();
    }
    
    void main()
    {
            Init_Device();
            InitSerial();
        printf ("Hello World\n");   /* Print "Hello World" */
            DetectFreq();
            printf("%lu", Freq);
            while(1);
    }
    
    

    Real Run Result:


    Hello World
    24500000 * 4 = 4294926936
    25690112 * 4 = 1568
    1568

    Our expect result:

    Hello World
    24500000 * 4 = 98000000
    25690112 * 4 = 102760448
    102760448
    


    I defined the variable as unsigned long, and unsigned long range is 0..4294967295.
    The 9800000 is far smaller than 4294967295, so I think there may exists a bug of Long Integer Multiple.

    conclusion:

    1.There are mistake of Long Integer Mutiple where open the on-chip arithmetic accelerator.

Reply
  • Long Integer Multiple Error. Target Options: MCU : C8051F120F, Use On-chip Arithmetic Accelerator.

    Source:

    #include <C8051F120.H>
    #include <stdio.h>
    
    unsigned long Freq;
    
    void DetectFreq()
    {
            unsigned long N;
            unsigned char M;
        SFRPAGE   = CONFIG_PAGE;
            M= PLL0MUL;
            switch (CLKSEL&0x03) {
                    case 00:        //Internal XTAL
                    case 03:
                                            Freq=25690112;//24.5L*1024L*1024L
                                            switch(OSCICN&0x03){
                                                    case 0x00: Freq/=8; break;
                                                    case 0x01: Freq/=4; break;
                                                    case 0x02: Freq/=2; break;
                                            }
                                            break;
    
                    case 01:        // External XTAL
                                            Freq=25L*1024L*1024L;
                                            switch (OSCXCN&0x70) {
                                                    case 0x03:
                                                    case 0x05:
                                                    case 0x07: Freq=Freq/2; break;
                                            }
                                            break;
                    case 02:        //PLL
                                            if (PLL0CN&0x04) { // External XTAL
                                                    Freq=26214400L;  //25L*1024L*1024L
                                                    N=Freq;
                                                    Freq*=PLL0MUL;
                                                    Freq/=PLL0DIV;
                                                    switch (OSCXCN&0x70) {
                                                            case 0x03:
                                                            case 0x05:
                                                            case 0x07: Freq=Freq/2; break;
                                                    }
    
                                            }
                                            else{
                                                    //Freq=25690112L;
                                                    Freq=24500000L;//25690112L;
                                                    N=Freq;
                                                    Freq*=PLL0MUL;
                                                    //FreqMul(PLL0MUL);
                                                    Freq/=PLL0DIV;
                                                    switch(OSCICN&0x03){
                                                            case 0x00: Freq/=8; break;
                                                            case 0x01: Freq/=4; break;
                                                            case 0x02: Freq/=2; break;
                                                    }
                                            }
                                            break;
            }
            SFRPAGE   = LEGACY_PAGE;
            printf("%lu * %u = ", N, M);
            printf("%lu\n", Freq);
    
            Freq=25690112L;
            printf("%lu * %u = ", Freq, 4);
            Freq*=4;
            printf("%lu\n", Freq);
    
    }
    
    void InitSerial()
    {
            SFRPAGE =LEGACY_PAGE;
        SCON0  = 0x50;                      /* SCON: mode 1, 8-bit UART, enable rcvr      */
        TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload        */
        TH1   = 221;                /* TH1:  reload value for 1200 baud @ 16MHz   */
        TR1   = 1;                  /* TR1:  timer 1 run                          */
        TI0    = 1;                  /* TI:   set TI to send first char of UART    */
    }
    
    // Peripheral specific initialization functions,
    // Called from the Init_Device() function
    void Reset_Sources_Init()
    {
        WDTCN     = 0xDE;
        WDTCN     = 0xAD;
    }
    
    void EMI_Init()
    {
        SFRPAGE   = EMI0_PAGE;
        EMI0CF    = 0x1F;
        //EMI0TC    = 0x4F;
               EMI0TC    = 0xCF;
    
    }
    
    void Port_IO_Init()
    {
        SFRPAGE   = CONFIG_PAGE;
        P4MDOUT   = 0xFF;
        P5MDOUT   = 0xFF;
        P6MDOUT   = 0xFF;
        P7MDOUT   = 0xFF;
        XBR0      = 0x07;
        XBR1      = 0x94;
        XBR2      = 0x40;
    }
    
    void Oscillator_Init()
    {
        data int i = 0;
        SFRPAGE   = CONFIG_PAGE;
        CCH0CN    &= ~0x20;
        SFRPAGE   = LEGACY_PAGE;
        FLSCL     = 0xB0;
        SFRPAGE   = CONFIG_PAGE;
        CCH0CN    |= 0x20;
        PLL0CN    |= 0x01;
        PLL0DIV   = 0x01;
        PLL0FLT   = 0x01;
        PLL0MUL   = 0x04;
        for (i = 0; i < 15; i++);  // Wait 5us for initialization
        PLL0CN    |= 0x02;
        //while ((PLL0CN & 0x10) == 0);
        CLKSEL    = 0x02;
        OSCICN    = 0x83;
    }
    
    // Initialization function for device,
    // Call Init_Device() from your main program
    void Init_Device(void)
    {
        Reset_Sources_Init();
        EMI_Init();
        Port_IO_Init();
        Oscillator_Init();
    }
    
    void main()
    {
            Init_Device();
            InitSerial();
        printf ("Hello World\n");   /* Print "Hello World" */
            DetectFreq();
            printf("%lu", Freq);
            while(1);
    }
    
    

    Real Run Result:


    Hello World
    24500000 * 4 = 4294926936
    25690112 * 4 = 1568
    1568

    Our expect result:

    Hello World
    24500000 * 4 = 98000000
    25690112 * 4 = 102760448
    102760448
    


    I defined the variable as unsigned long, and unsigned long range is 0..4294967295.
    The 9800000 is far smaller than 4294967295, so I think there may exists a bug of Long Integer Multiple.

    conclusion:

    1.There are mistake of Long Integer Mutiple where open the on-chip arithmetic accelerator.

Children
  • You didn't answer the question:

    Does the C8051F120F actually have an On-chip Arithmetic Accelerator?

    and, if it does, do the Keil tools support it?

  • sir heixi

    i loooked at C8051F120.H

    it is a cygnal C8051F120/1/2/3 or C8051F124/5/6/7 yes ????

    i found datasheeeet at
    www.kemt.fei.tuke.sk/.../c8051f12x.pdf

    it has lot of good peritherrals but i see not by on the on-chip arithmeratic accceleratoror??????!!!!!!

    do it have one you thinking??????

    if no then silly to set tick in ide probably

  • C8051F120 DataSheet said that: Page 157, Rev1.2
    13. MULTIPLY AND ACCUMULATE (MAC0)
    The C8051F120/1/2/3 devices include a multiply and accumulate engine which can be used to speed up many mathematical
    operations. MAC0 contains a 16-by-16 bit multiplier and a 40-bit adder, which can perform integer or fractional
    multiply-accumulate and multiply operations on signed input values in two SYSCLK cycles. A rounding
    engine provides a rounded 16-bit fractional result after an additional (third) SYSCLK cycle. MAC0 also contains a 1-
    bit arithmetic shifter that will left or right-shift the contents of the 40-bit accumulator in a single SYSCLK cycle.
    Figure 13.1 shows a block diagram of the MAC0 unit and its associated Special Function Registers.

  • yes i see

    i look at prelimanary data who does not have mac

    i look at newe data rev 1.4 at

    www.silabs.com/.../C8051F12x-13x.pdf

    has details in page 165

    do you errorr in ide or on hardare?????

    sir erac is very right with ide not emulater all devs

    if hardware is give error tell keil see they fix it??????

  • My Program runs on simulator .
    It runs out correct result on simulator when not use on-chip arichmetic accelerator.

  • but do it run correct on hardwaaare???!!!

    if just on simuletor then think it is simulater do not simelate good!!!!????

    then no be bug of compiler huh????

  • but do it run correct on hardwaaare???!!!

    if just on simuletor then think it is simulater do not simelate good!!!!????

    then no be bug of compiler huh????

    A SIMULATOR simulates and as such will NEVER give you the full (and correct) story. Also, as stated before, there is no way it is economically feasible for Keil to simulate every exotic function of all exotic derivatives of the '51.

    such special interest issues is what keeps Keil from taking time for general and important issues such as changing compiler things like
    mov r7,Ralph
    mov a,r7
    to
    mov a,Ralph
    in the COMPILER, not the optimizer

    If you doubt the simulator, try it on the hardware, stick the code on your devboard use the emulator and check. This is so darn simple and would have been resolved in 5 minutes instead of the DAYS these threads has run.

    Erik

  • "A SIMULATOR simulates and as such will NEVER give you the full (and correct) story"

    i not think you be right with NEVER!!!!!!

    a dedacated simulator for a specifec cpu is posssible to give correct story

    but point by me is that compiler probly do not have the bug whot he say before!!!

  • "A SIMULATOR simulates and as such will NEVER give you the full (and correct) story"

    i not think you be right with NEVER!!!!!!

    a dedacated simulator for a specifec cpu is posssible to give correct story

    a small correction:

    A SIMULATOR simulates and as such a simulator you can afford will NEVER ......

    re "a dedacated simulator for a specifec cpu" dream on.

    again: why not just spend 5 minutes and try it with your devboard and emulator instead if spending days discussing it

    Erik

  • sir eric

    again i sit in corner with hat on and think hard

    i do think we basicerally agree on point

    do you?????

  • i sit in corner with hat on and think hard

    WHY?

    STOP THINKING!!!! stick the stuff on a devboard, hook up the emulator and see the result. WHY ON EARTH 'think' about somethog you can (dis)prove in 5 minutes??????

    Erik

  • "The C8051F120/1/2/3 devices include a multiply and accumulate engine which can be used to speed up many mathematical operations."

    OK - the MAC engine can be used that way - but do the Keil tools support it?

    Does the option that you are selecting relate specifically to the MAC engine on the SiLabs C8051F120/1/2/3 devices?

  • "My Program runs on simulator"

    And so it should!
    The Simulator will simulate the on-chip arithmetic acccelerator that the tools expect - if your real hardware doesn't have such a feature, then it obviously won't work properly on that hardware!

  • Thanks all.

    to sir Eric
    it run correct on hardwaaare?
    My hardware circuit board is producing,
    and my board will connect several systems which are developping too.

    The communication protocol between systems is constitute.
    So We can program and debug synchronously.
    I developped the MCU program and a AGSI DLL for Simulator other systems.

    Even if run on the hardware, we cannot acquire other systems for debuging our hardware.

    So simulator is very important method for us.

    C8051F120 has 120KB Flash Code memory. My Mcu program size is 80KB now. and It would grown to 100KB or more.
    so emulator is download code to board slowly , and the mcu can be programed for limitted times, Then if debug it on hardware, we need offen repace the MCU.
    I closed the On-Chip Arithmetic Accelerator when simulating, I'll try on-chip accelerator on board,when finished simulation.

    to sir Andy
    OK - the MAC engine can be used that way - but do the Keil tools support it?
    Keil support the MAC of C8051F, On "Target Options", if you select other MCU such as "Intel 8051H", the "On-chip Arichmetic Accelerator" option will dispear.

  • "STOP THINKING!!!! "

    sir erac

    that is VERY bad idea you say me!!!

    persoon must think to design project!!!!

    it called planning you know

    i give you book on design for you be learning ????