Relaxation oscillators (for capacititive touch sensing)


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The significance is that you are trying to use features that your selected PIC does not have (TMR1GIF).

    So you will need to make more than syntax changes to get it to work.
    The overall method used will need to be different, and it's one that I have never investigated.
    <br>
    DT

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    The significance is that you are trying to use features that your selected PIC does not have (TMR1GIF).

    So you will need to make more than syntax changes to get it to work.
    The overall method used will need to be different, and it's one that I have never investigated.
    <br>
    Ok, roger that...I'm in the Sierra Hotel Indigo Tango (hey ho, two nights apparently wasted). Thanks for the early interjection at this point though ...I'd have ended up looking like a 'ZZ Top Guitarist after a night on the razzle' trying to sort this one myself.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Don't give up ...

    I'm sure it can be done.
    But copy/paste from a 16F726 program will only confuse you.

    You've got an Oscillator running ...
    So if the C2OUT pin were connected to the T1CKI pin, then Timer1 could count the pulses.

    Make a "Time Base" with Timer2 and the CCP1 pin (a.k.a. HPWM at lowest freq) connected to the T1G pin.

    Then use TMR2_INT to read the Timer1 value, which should be directly proportional to the frequency. Not sure how good the resolution will be, but that's what experimentation is for.
    <br>
    DT

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Thanks for the moral support (& the idea, which sounds great!)

    Like I say, I'm out my depth & frankly I need to go & learn about timers now (never had to use 'em before)

    So my next 'challenge' is o find a way of ensuring that Timer1 is seeing (counting) pulses in from C2out at the T1CKI Pin (I've a sneaking suspiscion, that that's going to be like drawing back teeth for me). I'm pretty sure it's not counting pulses yet, I took a bit of a flyer & lifted the parts I thought were most appropriate rom byte_butchers code...

    Code:
     
    DEFINE OSC 4
    DEFINE DEBUG_REG PORTA
    DEFINE DEBUG_BIT 0      ' RA0 = TX out to PICKit2 programmer USART tool
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0     ' 1 = inverted, 0 = true
    DEFINE	ADC_BITS 10     ' Set number of bits in result
    DEFINE	ADC_CLOCK 1     ' Set clock source Fosc/8 "2uS"
    DEFINE	ADC_SAMPLEUS 50 ' Set sampling time in uS
    
    CM1CON0= %10010100    'from the Microchip AN1011a application note.
    CM2CON0= %10100000    'from the Microchip AN1011a application note.
    CM2CON1= %00110010    'from the Microchip AN1011a application note.
    SRCON  = %11110000    'from the Microchip AN1011a application note.
    VRCON  = %10000111    'from the Microchip AN1011a application note.
    ANSEL  = %00001010    'AN1 & AN4 analogue, the rest Digital.
    TRISA  = %11111011            'RA1 (C12IN0-) as input, RA2 (C1Out ) output RA5 Input (T1CKI)  
    TRISC  = %00000011            'RC0 (VCC/4) as input, RC1 Input (not sure if it's in scope either), RC4 output (C2OUT)
    
    ' the above seems to get me my oscillator output.
    
    
    
    'Timer Setup   (all byte_butcher's code & likely not going to work with the 16F690)
    T2CON = %01110110 'bit7=unimplemented, bit6-3=postscaler, bit2=TMRON, bit1-0=prescaler 
    PR2 = %11111111       'give PR2 a number for TMR2 to match
    PIR1.1 = 0      'Clear the TMR2 interupt flag
    PIE1.1 = 1      'Turn TMR2 interrupt enable on
    T1CON = %11000101 'Timer clock source=CAPOSC, prescale=1:1, dedicated OSC disabled, no external clock synchronize, timer on
    PIR1.7 = 0   'Clear Gate Interrupt Flag
    PIR1.1 = 0   'clear the TMR2 interupt flag
    
    '-----Allocate Variables
    timercount   var    word  ' raw count from TMR1
    timercount = TMR1L + TMR1H << 8
    
    '----Main loop-----------------------------------------------------------
    Main:
        DEBUG " timerCount= ", DEC timercount, 13, 10
        pause 100  
    GOTO Main
    end
    (the 'timercount' onscreen DEBUG output remains steadfastly at zero.... I guess I'm gonna have to get deep down 'n dirty & try & figure out all those specific Timer register settings are for the 16F690!

    Once I'm sure my Timer1 is counting, then I guess I can enter the brave new world of getting creative with interupts!

    Thanks once again.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You're still copying from a 16F726 program ...
    Just forget about byte_butchers code. It doesn't apply, because there is no CSM in the 16F690!

    I'm purposely being vague here because you only spent 45 minutes on the last version. I know ... "pouring scorn" ...

    To select the T1CKI pin as input to Timer1, T1CON.1 (TMR1CS) should be set to 1.
    Other bits in T1CON might be different too.

    And when I hinted to HPWM, it should have been a big red flag.
    <br>
    _________________
    DT
    &nbsp; Fishing is cruel, why would anyone teach people to fish?

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Well thanks for checking back...and holding back on the scorn!

    I've got Timer1 counting now, here's the magic combination of 1 & 0's (just in case any other 16f690'ers wanting to get their relaxation oscilator working into Timer1 & stumble upon this thread via Google)...

    T1CON = %10000111

    Also....

    Code:
    '-----Allocate Variables
    timercount   var    word  ' raw count from TMR1
    
    '----Main loop-----------------------------------------------------------
    Main:
    timercount = TMR1L + TMR1H << 8
        DEBUG " timerCount= ", DEC timercount, 13, 10
        pause 50  
    GOTO Main
    end
    .....of course the bit in bold needed to be in my loop....else I'd always have the same timer1 value showing up onscreen.

    Anyway, not a totally unsuccessful night...got my oscillator oscillating and my timer1 incrementing - gotta pull all this together now with something like you've suggested Darrel. (I can't help but base my code on others ....even if it only applies loosely - I have to start with something & start stripping away the bits I don't need - if nothing else it shows me what registers are in play & forces me to try & understand them!)

    & so....to bed.

    Thanks to you all for bearing with me in my somewhat 'white noisy' thread.

    PS: Just so I've something to wake up to in the morning, what's wrong with this high level concept for measuring the incoming frequency at Timer1 input....

    Clear Timer0 (have it counting the internal clock)
    When Timer0 overflows (which should always be the same time period?), use the Timer0 'overflow interupt' to then trigger a bit of code to read in the contents of timer1
    if the contents of timer1 is more or less the same as the previous sample content, then no finger has gone near the sensor, if the value is significantly lower, then essentially a pseudo-button has been pressed
    Clear timer 1
    Clear timer 0
    rinse, repeat?


    [dives for cover waiting to be shot down in flames]
    Last edited by HankMcSpank; - 23rd November 2009 at 01:07.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    A total count from Timer1 is a start!
    Relate it to a period of time, and your good, beit Timer0 or Timer2.

    <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/yCir5Wwpvos&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/yCir5Wwpvos&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
    DT

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts