Announcement

Announcement Module
Collapse
No announcement yet.

How do i measure the time between each C-code instruction and time taken to....

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do i measure the time between each C-code instruction and time taken to....

    Hi ....

    I am a new to this micro-controller world and just practiced few basic programs using 8051 and PIC.
    My project is on temp sensing using ds1820 i.e 5 ds1820 IC's on single wire. i'm using PIC18f452-12MHz Xtal, MPLAB. I need to achieve 1usec time delay.
    PIC18f takes 4 clock cycles per instr. That means each instr will take 3MHz = 0.33usec. Using this value i made a delay for-loop with value 3 to achieve 1usec delay. But i;m not sure what exactly is the delay inside the PIC when i program it. I don't have a CRO to measure the delay.
    So please please help me

    My concern is ....
    'How do i measure the time between each C-code instruction and time taken to get into and come out of any function(returning or non returning any value)....'

  • #2
    Hi Abdul

    Let's not go deep into the architecture and associated data sheets of microcontroller PIC18F452 to address your concern.

    The source code program which you have developed is translated to the target machine language by the assembler. Assuming that you have coded it in a C compiler targeting the PIC series of microcontrollers, the compiler itself compiles the entire source code to the target machine language, allocates memory for storing program, data, stack etc. Thereafter, the microcontroller executes only the machine language code and the clock cycles needed for executing each instruction generally varies from instruction to instruction and controller to controller.

    It is a standard programming practice to create a delay loop by assigning NOP (No operation) for specified number of clock cycles such that the programmer generates the desired delay. In your case, the 1 micro second delay will be achieved by performing 'No OP' for three clock cycles.

    The other probable delay inside the microcontrller is only the propagation delay, which is almost negligible for all practical purposes.

    The best way to measure delay using an oscilloscope is to generate a square wave of desired values (peak, delay) by writing small piece of code, capture the waveform in an oscilloscope and measure the delay thereafter. By doing so, you can compare the expected delay from the program and actual delay observed on the oscilloscope to draw inferences.

    Comment


    • #3
      Use keil

      Originally posted by Vidya1967 View Post
      Hi Abdul

      Let's not go deep into the architecture and associated data sheets of microcontroller PIC18F452 to address your concern.

      The source code program which you have developed is translated to the target machine language by the assembler. Assuming that you have coded it in a C compiler targeting the PIC series of microcontrollers, the compiler itself compiles the entire source code to the target machine language, allocates memory for storing program, data, stack etc. Thereafter, the microcontroller executes only the machine language code and the clock cycles needed for executing each instruction generally varies from instruction to instruction and controller to controller.

      It is a standard programming practice to create a delay loop by assigning NOP (No operation) for specified number of clock cycles such that the programmer generates the desired delay. In your case, the 1 micro second delay will be achieved by performing 'No OP' for three clock cycles.

      The other probable delay inside the microcontrller is only the propagation delay, which is almost negligible for all practical purposes.

      The best way to measure delay using an oscilloscope is to generate a square wave of desired values (peak, delay) by writing small piece of code, capture the waveform in an oscilloscope and measure the delay thereafter. By doing so, you can compare the expected delay from the program and actual delay observed on the oscilloscope to draw inferences.


      Here As you don't have an OSC I would suggest you using some free software's like KEIL and test the register values and then use the counter/timers in it to have the delay u required.
      That would be the best possible way u can go a head...

      Thanks,
      Manoj

      Comment


      • #4
        There is another way which might be helpful in finding out...that is - sifting through listing file (.lss), it will have assembly codes with mnemonics mentioned (basically assembly program converted from C program by compiler). There you can find which exact instructions are being used for delay and since you know time needed for each instruction, you can find out actual delay being burned into the microcontroller.

        Comment


        • #5
          .lss file Which IDE has this option..???

          Originally posted by Knewron View Post
          There is another way which might be helpful in finding out...that is - sifting through listing file (.lss), it will have assembly codes with mnemonics mentioned (basically assembly program converted from C program by compiler). There you can find which exact instructions are being used for delay and since you know time needed for each instruction, you can find out actual delay being burned into the microcontroller.
          I was waiting for this response... But can you specify where can i get this .lss file ... i mean which compiler generates it.? As i use MPLAB for PIC... If any other IDE for any micro-controller... Please specify...

          Comment


          • #6
            where can i get this .lss file
            The .lss file is generated by the compiler during compiling the program and converting it into .hex file. You should check (should have checked already) the directory in which your .hex file is located, in the same directory this listing file should be present. It may be with another extention too. As we don't use MPLAB, can't tell which file exactly, but with Keil and AVR Studio, the extension is .lss.

            Link: https://www.google.co.in/url?sa=t&rc...44770516,d.bmk

            Comment


            • #7
              Can anyone.. give me code for a perfect 1usec or 2usec Delay using 12Mhz-18f ,MPLAB..

              Originally posted by Abdul View Post
              Hi ....

              I am a new to this micro-controller world and just practiced few basic programs using 8051 and PIC.
              My project is on temp sensing using ds1820 i.e 5 ds1820 IC's on single wire. i'm using PIC18f452-12MHz Xtal, MPLAB. I need to achieve 1usec time delay.
              PIC18f takes 4 clock cycles per instr. That means each instr will take 3MHz = 0.33usec. Using this value i made a delay for-loop with value 3 to achieve 1usec delay. But i;m not sure what exactly is the delay inside the PIC when i program it. I don't have a CRO to measure the delay.
              So please please help me

              My concern is ....
              'How do i measure the time between each C-code instruction and time taken to get into and come out of any function(returning or non returning any value)....'


              hi, all...

              Can anyone.. give me code for a perfect 1usec or 2usec Delay using 12Mhz-PIC18f ,MPLAB.. Which is "verified using CRO.." Please..

              Comment


              • #8
                Originally posted by Abdul View Post
                hi, all...

                Can anyone.. give me code for a perfect 1usec or 2usec Delay using 12Mhz-PIC18f ,MPLAB.. Which is "verified using CRO.." Please..

                after requesting and running from pillar to post i found 1 CRO.

                this is the verified code...
                void main(void)
                {
                int i;
                TRISBbits.TRISB7 = 0;

                while(1){

                PORTBbits.RB7=0;
                //for(i=0;i<3;i++);
                DS1820_DelayUs(3);
                PORTBbits.RB7=1;
                //for(i=0;i<3;i++);
                DS1820_DelayUs(3);
                }
                }


                void Delay(unsigned char a)
                {
                int i,j;
                for(i = 0; i < a; i++)
                for( j = 0; j < 3; j++);
                }

                void DS1820_DelayUs(int val)
                {
                int k;
                for(k=0;k<val;k++);
                }

                Delay(1); 52usec LOW AND 52USEC HIGH

                Delay(2); 88USEC LOW 88USEC HIGH
                Delay(3); 125USEC LOW 125USEC HIGH
                36 USEC INRCM FOR EACH SINGLE DELAY WITH FUNCTION CALLING TIME 16USEC
                **********************************
                PORTBbits.RB7=0;
                i=7;
                PORTBbits.RB7=1;
                i=5; // 1.4usec low and 2.1usec high.

                **********************************

                for(i=0;i<1;i++); 13usec LOW AND 14USEC HIGH
                for(i=0;i<2;i++); 19usec LOW AND 20USEC HIGH
                for(i=0;i<3;i++); 26usec LOW AND 26USEC HIGH

                EACH FOR LOOP COUNT IS 7USEC DELAY

                **********************************

                DS1820_DelayUs(1); 25usec low and 26usec high
                DS1820_DelayUs(2); 35usec low and 36usec high
                DS1820_DelayUs(3); 44usec low and 45usec high


                ******/

                Comment


                • #9
                  1us

                  for 1us just put:

                  NOP
                  NOP
                  NOP

                  in your program.

                  Comment

                  Working...
                  X