Confused at the function "pulseIn()"
hello everyone, working on rc signal mixed system. , found useful library function: pulsein()
i interested @ function's completed, found source code @ arduino-1.0.5/hardware/arduino/cores/arduino/wiring_pulse.c
i confused solution returned.
and annotate says:
// loop has been determined
// 20 clock cycles long , have 16 clocks between edge
// , start of loop. there error introduced by
// interrupt handlers.
then why width multi 21?? why not 22 or multi 20 , plus constant? how guys work out it?
i interested @ function's completed, found source code @ arduino-1.0.5/hardware/arduino/cores/arduino/wiring_pulse.c
i confused solution returned.
code: [select]
return clockcyclestomicroseconds(width * 21 + 16);
and annotate says:
// loop has been determined
// 20 clock cycles long , have 16 clocks between edge
// , start of loop. there error introduced by
// interrupt handlers.
then why width multi 21?? why not 22 or multi 20 , plus constant? how guys work out it?
in case, code in assembly make immune compiler changes , count number of cycles.
in lieu of coding in assembly, use avr-objdump create assembly listing , count cycles. use python script wrap avr-objdump (named "ds.py" dump sketch)...
code: [select]
import fnmatch
import os
import subprocess
import string
pathok = false
pathlist = os.environ['path'].split( os.pathsep )
for path in pathlist:
testme = os.path.join(path,'avr-objdump.exe')
if os.path.exists(testme):
pathok = true
break
if not( pathok ):
arduinoroot = 'c:\\arduino\\arduino-1.0.5\\'
pathlist.append( arduinoroot + 'hardware\\tools\\avr\\utils\\bin' )
pathlist.append( arduinoroot + 'hardware\\tools\\avr\\bin' )
pathlist.append( arduinoroot + 'hardware\\tools\\avr\\etc' )
pathnew = os.pathsep.join( pathlist )
os.environ['path'] = pathnew
tempdir = os.environ.get('temp')
tempfile = os.path.join(tempdir,'junk.cpp')
matches = []
for root, dirnames, filenames in os.walk(tempdir):
filename in fnmatch.filter(filenames, '*.elf'):
matches.append(os.path.join(root, filename))
matches.sort( key=os.path.getmtime )
if len(matches) > 0:
f = open(tempfile, 'w')
subprocess.call(['avr-objdump.exe','-s','-z',matches[len(matches)-1]],stdout=f)
f.close()
os.system( 'start ' + tempfile )
Arduino Forum > Using Arduino > Microcontrollers > Confused at the function "pulseIn()"
arduino
Comments
Post a Comment