Announcement

Collapse
No announcement yet.

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

Collapse
X
  • 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

                  Fresh & New Discussions

                  Collapse

                  Most Discussed

                  Collapse

                  • trdelectronics
                    What type of discussion i should start to engage this forum members?n
                    trdelectronics
                    I already published some threads but most of the time didn't get satisfied answer, may be there are enough number of members in this forum.
                    Do...
                    July 29th, 2016, 05:48 PM
                  • Ronie1988
                    High Voltage DC Measurement
                    Ronie1988
                    I need to measure High Voltage DC ranging from 300V to 500V. Is there any way of measuring some specific ICs or sensors. I don't want to use voltage dividers...
                    August 7th, 2016, 08:56 PM
                  • trdelectronics
                    Can we use any DSLR Cameras directly to AC?
                    trdelectronics
                    Is there any way to use DSLR Camera directly to electric current. If yes then is it reliable to use DSLR Camera with direct electric current.
                    August 10th, 2016, 08:48 PM
                  • Sterana1
                    Sterana1
                    Hi Admin I want some e books on the help of programming pic16f690 microcontroller because i want to do my desing by using a pic and LCD any ideas are...
                    August 9th, 2016, 07:33 AM
                  • rss.srinivas
                    rss.srinivas
                    Iam getting constant output of 4.v DC (2amp) from a voltage source,as i want to use 3.3v zener diode instead of 3.3v regulator ic(lm117)
                    for arm7
                    ...
                    July 30th, 2016, 11:36 AM
                  • mkbutan
                    ESP8266 ESP 12e Not responding to AT Commands
                    mkbutan
                    Hi everyone,How are you?
                    I have two ESP8266 ESP-12e Wi-Fi Modules ...
                    I have also updated the Arduino IDE Ver to the Latest one ei 1.6.10...
                    August 1st, 2016, 11:40 PM
                  • Saurabh Durgapal
                    uploading data directly to the cloud
                    Saurabh Durgapal
                    Is there any software which uploads data coming to the RS 232 port of computer to cloud server?
                    August 2nd, 2016, 12:31 PM
                  • krish2nasa
                    krish2nasa
                    IoT, Home Automation, Smart Cities, AI, Renewable Energy,Energy Harvesting, Embedded Systems, Microcontrollers, ARM Cortex-M0+, PIC16LFxxxx, Wireless...
                    August 3rd, 2016, 05:07 PM
                  • Sandeep Soni
                    Sandeep Soni
                    sir i am beginner...i want to learn designing microcontroller projects. From all the post here in this forum i found Arduino uno to be easier...pls guide...
                    August 6th, 2016, 05:51 PM
                  • allan10
                    About impedance matching PCB Design???
                    allan10
                    In the high-speed PCB design in order to prevent reflection should consider impedance matching, but the PCB processing technology limits the impedance...
                    August 11th, 2016, 01:34 PM

                  What's Going On

                  Collapse

                  There are currently 1380 users online. 1 members and 1379 guests.

                  Most users ever online was 3,698 at 08:31 PM on June 5th, 2016.

                  Working...
                  X