Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

400 nanoseconds delay time with 12F683

cosmok82
2014-01-17
2014-01-18
  • cosmok82
    cosmok82
    2014-01-17

    Hi friends, I'd like to fix a delay time of minimum 400ns (maybe with an external clock), but the minimum time delay with "wait" icon is 1us and 0.4us isn't accepted. Do you have any solutions?

     
  • Marcoos
    Marcoos
    2014-01-17

    Hi

    400ns seem a very short time for a microcontroller to control, even using a 20 MHz quartz I suggest a "NOP".
    Ciao

     
    • cosmok82
      cosmok82
      2014-01-17

      What's a "NOP"?

       
  • Marcoos
    Marcoos
    2014-01-17

    a single assembler instruction delay
    Ciao

     
    • cosmok82
      cosmok82
      2014-01-17

      Could someone explain me how to generate a NOP? Please.
      PS
      I found NOP = No Operation instruction. Not a real delay.

       
      Last edit: cosmok82 2014-01-17
  • cosmok82
    cosmok82
    2014-01-18

    If I understand correctly, the NOP instruction doesn't execute instruction for N cycles of clock, but what's the value of N?

     
  • mmotte
    mmotte
    2014-01-18

    As always get the Data Sheet for your processor and read it.

    //// One instruction cycle consists of four oscillator periods;
    for an oscillator frequency of 4 MHz, this gives a
    nominal instruction execution time of 1 μs. All
    instructions are executed within a single instruction
    cycle, unless a conditional test is true, or the program
    counter is changed as a result of an instruction
    /////

    This is Quoted from the data sheet

    NOP like most pic instructions use 1 instruction cycle.

    What is your osc frequency?

    to get 400 nanosec you would need 20 Mhz osc and execute 2 NOP's in a row.

     
  • cosmok82
    cosmok82
    2014-01-18

    I thought the context it was this, but i preferred to ask you. Thanks mmotte!

     
  • mmotte
    mmotte
    2014-01-18

    using NOP 's in GCBasic is easy because assembler instructions can be embedded into the code and used just like basic instructions.

    I have seen code where 10 or more NOP's are used in a row for timing.

    You would think that for code compactness you would put the NOP in a FOR loop or REPEAT loop but remember that the loops have "over head" which means additional instructions that take up time. Many times I have used FOR loops to waste time when the amount of time was not important. You would look at the assembler for a FOR loop to seen what additional instructions were added.