Bruce,
Does posting all the examples of late mean that you are getting closer with your book?
Thanks for all of the examples!!!
Bruce,
Does posting all the examples of late mean that you are getting closer with your book?
Thanks for all of the examples!!!
Dave
Always wear safety glasses while programming.
Dave,
No. It's just a few things people have asked me for. I prefer to post if here for everyone
rather than sending it to just a few by email. Still working on that book too. It's just slow
with the economy in the tank, and working 12-16 hours a day to stay afloat...;o)
The newer PIC's such as the PIC16F690 and the 28/40-pin PIC18FxxJ11 families have a Timer1 module with Gate Control which is ideal for doing this sort of thing.
6.6 Timer1 Gate
Timer1 gate source is software configurable to be the
T1G pin or the output of Comparator C2. This allows the
device to directly time external events using T1G or
analog events using Comparator C2. See the
CM2CON1 register (Register 8-3) for selecting the
Timer1 gate source. This feature can simplify the
software for a Delta-Sigma A/D converter and many
other applications.
Timer1 gate can be inverted using the T1GINV bit of
the T1CON register, whether it originates from the T1G
pin or Comparator C2 output. This configures Timer1 to
measure either the active-high or active-low time
between events.
That'll work too ... if you have a PIC with the TMR1 gate option.
Code:' PIC12F609 using Timer1 gate input to record pulse widths @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _IOSCFS_4MHZ & _CP_OFF CMCON0 = 0 ' comparator disabled CMCON1 = %00000010 ' TMR1 gate source is T1G pin GPIO = 0 ' outputs all low at POR TRISIO = %00010000 ' GPIO.4 = TMR1 gate input PVAL VAR WORD ' holds pulse time TMR1H = 0 TMR1L = 0 T1CON = %11000001 ' TMR1 gate active-high, Fosc/4 clock, TMR1 on Main: ' apply a pulse < 65536uS to TMR1 gate input GPIO.4 to use WHILE !GPIO.4 ' wait for high signal to trigger TMR1 gate pin WEND WHILE GPIO.4 ' wait for signal to return low (stops TMR1) WEND PVAL.LowByte = TMR1L ' get TMR1 counts into PVAL PVAL.HighByte = TMR1H ' from TMR1 TMR1H = 0 ' reset TMR1 TMR1L = 0 GOTO Main END
Would it be possible for you to do a non-blocking version of Measuring signal pulse widths with capture module.
Definitely. Just let CCP1 generate an interrupt, and handle flipping CCP1CON.0 + grabbing
results in T1/PW in the interrupt handler.
For all the NOOBS (like me) don't forget theto make your T1G pin a digital input. I spent a couple hours scratching my head trying to figure out why I couldn't get this code to run on my 12f683......that was all I needed.Code:ANSEL=0
Thank you Bruce for the code snippets...can't wait for the book. I actually got started with micros about 10 years ago with the help of your website. I'm only coming back to working with them in the last few months, and your code is helping me again!
Hi Picone,
Glad I could help, and welcome back.
FYI: Darrel has a nifty include file you can use to disable all analog features by just including it in your code. See this thread http://www.picbasic.co.uk/forum/showthread.php?t=11100
It's pretty handy when you forget to disable A/D it takes care of it for you.
Bookmarks