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

    Quote Originally Posted by HankMcSpank View Post
    I saw DT's reply on that thread ( http://www.picbasic.co.uk/forum/show...00&postcount=5) & have modified the DTS-INTS-14.Bas file in accordance with his instructions (& the other bits & bobs), but when I come to compile I get a whole heap of erroRs along the lines of TMR1GIF Symbol not previously defined in the ASM file....????
    The 16F690 does have a Gate control on Timer1.
    But it doesn't have a TMR1GIF bit, and doesn't generate interrupts for the gate.
    <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 16F690 does have a Gate control on Timer1.
    But it doesn't have a TMR1GIF bit, and doesn't generate interrupts for the gate.
    <br>
    Hmm (rubs chin, pretending to understand the significance of what you're saying - but nevertheless knowing full well it's *BAD*). As it goes, I was just about to say, I'm getting this when I compile...

    "Symbol not previously defined (TMR1GIF)" (which may/may not be related to what you're saying, l- modified your files as per your instructions to byte_butcher - I'm out my depth at the moment...but learning fast!)

    From the Microchip application note- http://ww1.microchip.com/downloads/e...tes/01101a.pdf (which embraces this method with the 16F690)...

    "Once the oscillator is constructed, its frequency must
    be monitored to detect the drop in frequency caused by
    a finger press. Figure 5 shows a more complete schematic
    where C2OUT not only drives the oscillator, but
    also is fed into the clock input of Timer1, T1CKI. Each
    time C2OUT changes from ‘0’ to ‘1’ Timer1 will increment.
    Unhindered, Timer1 will increment non-stop and
    eventually roll over, but this is not useful for capacitive
    sensing.
    To make it useful, a fixed time base is used to measure
    the frequency over a defined period. Timer0 provides
    this fixed period time base. At the start of a measurement,
    Timer0 is cleared, and it will count up to 255 and
    then it will overflow. On overflow, the Timer0 interrupt,
    T0IF, causes the program to vector to the Interrupt Service
    Routine.
    "



    As a beginner, could you tell me the significance of your news...

    1. I can't use your interupt routines?
    2. Their proposed method wont work? even though from the same datasheet, they say this ...

    "There are currently three families of PIC microcontrollers
    able to use the method as shown. These are the
    Microchip PIC16F616 family, PIC16F690 family and
    PIC16F887 family."


    Grateful for the clarification!
    Last edited by HankMcSpank; - 22nd November 2009 at 22:19.

  3. #3
    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

  4. #4
    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.

  5. #5
    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

  6. #6
    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.

  7. #7
    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?

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