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

                  • vairamanisjc
                    vairamanisjc
                    i have sent the abstract and in that i have mentioned that i need WICED™ SenseBluetooth® Smart Sensor Development Kit for my project
                    Yesterday, 10:21 AM
                  • ElectronicsForYou
                    How Forum member ranks are allotted
                    ElectronicsForYou
                    Ranks are allotted according to the number of posts made by a forum member.

                    Here is the summary:
                    User Title Minimum Posts
                    Newbie 0
                    Junior Member 10
                    Experienced Member 50
                    ...
                    April 26th, 2016, 03:57 PM
                  • RAMAKANTA
                    RAMAKANTA
                    aansari155 , happy birthday .. many many happy returns of the day..
                    April 25th, 2016, 09:58 AM
                  • RAMAKANTA
                    RAMAKANTA
                    Happy birthday Altaf Jeelan. many many happy returns of the day
                    April 25th, 2016, 09:57 AM
                  • RAMAKANTA
                    RAMAKANTA
                    Happy birthday Hany elkholy. many many happy returns of the day
                    April 25th, 2016, 09:56 AM

                  Most Discussed

                  Collapse

                  • Sujit Mishra
                    Menu & Sub-Menu for PIC16F877A
                    Sujit Mishra
                    Hello friends,

                    Can anyone tell me how to make menu and sub- menu system for ADC in PIC16F877A. I mean I want to change the reference voltage...
                    April 9th, 2016, 12:54 PM
                  • Sujit Mishra
                    5 watt smd led in series.
                    Sujit Mishra
                    I need to how much current and voltage is required to drive a 2x5 watt led in series?
                    April 15th, 2016, 06:48 PM
                  • Gaurav Mishra
                    Raspberry Pi to Raspberry Pi communication using UART
                    Gaurav Mishra
                    I am working on a project that requires text/img to be sent via UART to the other raspberry pi. I tried using minicom but I am facing problems.
                    ...
                    April 7th, 2016, 01:42 AM
                  • meetdilip
                    Build a Step up for home use
                    meetdilip
                    I am a complete beginner. At my home, we have very serious low voltage condition. I need to make a Step up transformer unit to make at least water pump...
                    April 23rd, 2016, 05:58 PM
                  • ina
                    Replacing EEG
                    ina
                    Hello! I have a project which consists in: a mind controlled robot using arduino.The device called electroencephalography(EEG) can catch the electric...
                    April 16th, 2016, 07:28 PM
                  • Gopiraja
                    Print Hex value on lcd
                    Gopiraja
                    I want to print 16 char hex (64bit) value on lcd display. Anyone give embedded c code for it. Thanks in advance.
                    April 2nd, 2016, 12:14 AM
                  • ElectronicsForYou
                    Congratulations to all the winners of March, 2016 !!!
                    ElectronicsForYou
                    Congratulations to all the winners of March, 2016 !!! Forum winners 1. Gaurav Mishra 2. mkbutan 3. Jagdish 4. Ramakanta 5. ledlive Please send in yours- 1) Name: 2) Email Address: Deadline - 10th of April, 2016. Gift: Amazon Gift Cards *For Interna...
                    April 5th, 2016, 03:20 PM
                  • Sujit Mishra
                    Sujit Mishra
                    Is there anyone who can write a embedded 'C' code for PIC16F877A in Gurgaon/ Delhi. Plz send me your details...
                    March 31st, 2016, 11:07 AM
                  • ElectronicsForYou
                    Motion Detection
                    ElectronicsForYou
                    @Parinita Agarwal "I am working on a project based on home automation. I am finding problem in android code. Actually, I am unable to write code to send...
                    April 1st, 2016, 03:11 PM
                  • ElectronicsForYou
                    USB to SATA converter chip
                    ElectronicsForYou
                    Suresh Babu: "Where can I get USB to SATA converter chip like TUSB9261 in India online?"
                    April 5th, 2016, 12:41 PM

                  What's Going On

                  Collapse

                  There are currently 286 users online. 1 members and 285 guests.

                  Most users ever online was 1,487 at 06:28 PM on March 12th, 2016.

                  Working...
                  X