Menu

PIC12F675 wait issue

sfyris
2016-01-27
2016-01-28
  • sfyris

    sfyris - 2016-01-27

    In the following code all is going well except of three things.
    a. After compile I have a warning: "Inaccurate microsecond delay due to use of variable at the current clock speed"
    b. Checking in oscilloscope the outgoing pulse is 3ms intead of 1ms it should be
    c. When using a constant value like wait 1000 us the timing is ok
    How can I sort this (the use of a word variable is necessary in my application)
    Using "pulseout outputpin, variable us" results in same issues
    These issues don't happen if using "wait byte_variable 10us" but then we can't use large values (255 is the limit)

    ;Chip Settings

    -#chip 12F675,4

    ;Defines (Constants)
    -#define GLOW_LED GPIO.2

    ;Variables
    Dim flag As integer
    Dim pulsew As word
    Dim GPIO As byte
    Dim gen_counter As byte

    ;Interrupt Handlers
    On Interrupt Timer0Overflow Call mypulseout

    Dir GLOW_LED Out
    pulsew = 1000
    gen_counter = 20
    flag = 0
    InitTimer0 Osc, PS0_1/4

    redo:
    Goto redo

    Sub mypulseout
    gen_counter = gen_counter + 1
    if gen_counter > 19 then
    Set GLOW_LED On
    wait pulsew us
    Set GLOW_LED Off
    gen_counter = 0
    end if
    End Sub

     

    Last edit: sfyris 2016-01-27
  • David Stephenson

    When working at a clock speed of 4MHz it should take about 1us to execute one ASM instruction.
    Trying to get accurate us delays when you are pulling a value from RAM is difficult, then you have the overheads in the delay loop.
    If it does not matter about accuracy no problem, but if it does you need a high clock rate which on a 12F675 means a crystal oscillator.
    Even so there will be some overheads in the compiled delay loop and even more so if the delay is a word rather than a byte.

     
  • sfyris

    sfyris - 2016-01-28

    A ok I understood. So I adapted the value of my variable to have the proper pulse timing. After few experiments I found that a value of 1000 is good enough to have an output of 3ms and a value of 230 to have 1ms. Thanks for help David.

     

    Last edit: sfyris 2016-01-28

Log in to post a comment.