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

                  • Aravind Putrevu
                    How to calculate amount of water flown in a pipe ? Sensors ?
                    Aravind Putrevu
                    Hi,

                    I have a question.

                    How to calculate amount of water flown in a pipe ? Is there any specific sensor that i can build up or...
                    August 29th, 2015, 08:35 PM
                  • ElectronicsForYou
                    Favourite Development Board
                    ElectronicsForYou
                    Which is your Favourite Development Board and why?

                    It should consider various parameters like Price, Quality, Compatibility, Ease of Use, etc.
                    August 28th, 2015, 02:20 PM
                  • Vivekgv
                    need help to choose a right technology
                    Vivekgv
                    Dear All,

                    I am working on a industrial IOT requirement for which I have to build a prototype.
                    Since in this group many of you guys...
                    August 5th, 2015, 04:31 PM
                  • khiremandar
                    CE certifed Voltage Stabilizer for Home?
                    khiremandar
                    Hi,
                    I am Mandar Khire. I live at Pune, Maharashtra.
                    This is my 1st question at this forum.
                    I am looking for voltage stabilizer for home...
                    August 12th, 2015, 03:45 PM
                  • Ayush Jain
                    AVR USB INTERFACE
                    Ayush Jain
                    Hey,
                    I have made a project with AVR and have interface that to PC using MAX232 and Serial to USB convertor. I need to remove both MAX232 and serial...
                    August 19th, 2015, 07:49 PM
                  • Amit7432
                    Quadcopter
                    Amit7432
                    Hey guys I'm working on quadcopter for minning industry and just need to know which camera should i use so that it suits the conditions. My supervisor...
                    August 29th, 2015, 04:52 PM
                  • Tibzitsohn
                    Tibzitsohn
                    Often it is seen whether it is child or adult person they have great lacking of concentration while they cannot concentrate their minds on one specific...
                    August 5th, 2015, 01:31 PM
                  • vini9213
                    Design of Dc to Dc converter
                    vini9213
                    For a series hybrid electrical vehicle,the power from the engine(1000rpm,60v,25A,gear ratio 1:3) 1.5kw is given to the six 8v lead acid batteries. So...
                    August 18th, 2015, 03:06 PM
                  • Jagdish
                    Jagdish
                    U check low weight blade. Than according to blade u select motor. Blade may be some plastic type material.. As weight increase more powerful motor require...
                    August 21st, 2015, 10:20 AM
                  • Anshul Gupta
                    oscillator
                    Anshul Gupta
                    what is the difference between 455khz resonator and a RC oscillator
                    August 22nd, 2015, 07:35 PM

                  What's Going On

                  Collapse

                  There are currently 66 users online. 0 members and 66 guests.

                  Most users ever online was 964 at 06:33 PM on July 12th, 2015.

                  Working...
                  X