Relaxation oscillators (for capacititive touch sensing)


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default Relaxation oscillators (for capacititive touch sensing)

    I have a 16F690, that I'd like to use in a capacitive touch sensor setup.

    I should set out my stall, I'm still very new to PIC programming & the confusing array of registers to set!

    The first part of getting capacititive touch sensors to work with the PIC, is to setupthe PIC's comparators in a relaxation oscillator config.

    I can't get it to work! (so I've essentially failed at the first hurdle!)

    Here's their simple schematic here (source = http://ww1.microchip.com/downloads/e...tes/01171B.pdf) ...



    ...which I've mapped the same 16f690 pins 'in play' here...




    that said, I don't understand why there are two 16f690 pins with C12IN- on them pins 15 & 18 as seen on this datasheet pinout extract...



    So RC0, RC1 & RC4 are the only ones of importance to get the relaxation oscilator, erhm oscillating! (or maybe RA1 - depending on which C12IN- Pin I should be using! What's the difference between the two pins marked c12in-?)


    Microchip have released an application note which outlines the register settings needed to setup the relaxation oscillator on a 16F887 - http://ww1.microchip.com/downloads/e...tes/01101a.pdf Appendix A (but not a 16f690), so I needed to translate these register settings over to the 16F690, which as it turns out, I reckon are the same as the 16f887 anyway...
    Code:
    CM1CON0 = %10010100
    CM2CON0 = %10100000
    CM2CON1 = %00110010
    SRCON = %11110000
    VRCON = %10000111
    but I'm struggling with the ANSEL register. On the 16f690, it seems that there are two ANSELS in play (ANSEL & ANSELH), and if my understanding is correct, these registers setswhether the corresponding pins are analogue or digital. So for the relaction oscillator, they'd need to be analogue.

    If I'm reading the pic16f690 datasheet correctly ( http://ww1.microchip.com/downloads/e...Doc/41262C.pdf )

    it seems that the only analogue pins I'm using are

    RC0 (Pin 16 , AN4)
    RC1 (Pin 15, AN5)
    RC4 is not an analogue pin?
    RA5 (Pin 18, AN1, again not sure if it's this C12IN- or the other one on pin 15!)

    therefore should my ANSEL register look something like this...
    Code:
    ANSEL=  %00110001
    ANSELH = 0

    Any other input greatfully received!


    PS I've read the post by byte_butcher (http://www.picbasic.co.uk/forum/show...t=byte_butcher) , but he used a 16F726 which has an inbuilt capacitive sensing module - I'd rather stick with the 16f690 which is apparently capable of capacitive touch sensing too.
    Last edited by HankMcSpank; - 20th November 2009 at 00:48.

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    I realise, that this whole relaxation oscillator melarkey is a little niche, but I only seek a little hand holding on some of the more simpler(to you guys/gals at least) registers (that said, I'm surprised that there aren't many many more people chomping at the bit to get funky proximity touch sensor switches working on there PICs)


    It seems there's a whole heap of errors abounding wrt 16f690, relaxation oscillators, schematics, & comparator naming etc (Microchip have released a newer datasheet too). The best schematic I've found wrt setting up the 16F690 as a relaxation oscillator is this one (it seems right)...




    With that schematic above in focus , could someone at least confirm I'm on the right track with the following simpler registers at least (there's a whole heap more register I have to configure, buit it'd be nice to eliminate these from my enquiries)

    Code:
    TRISA  = %11111111            'All inputs ...RA1 (C12IN0-) input 
    TRISC  = %00000001            'RC0 (VCC/4) input RC4 output (C2OUT)
    
    ANSEL  = %11111111             'All Analogue ....becuase relaxation oscillator pins are analogue-ish  &not digital as far as I can see!
    ANSELH = %11111111            'All Analogue
    Last edited by HankMcSpank; - 21st November 2009 at 23:46.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Going back to your first post...

    There is a difference... pin 18 is C12IN0- and pin 15 is C12IN1-

    This is taken from my Datasheet DS41262E (yours might be an extinct version).

    You asked about RC4. Whether you consider a Comparator OUTPUT as analog I suppose is up to you. I consider Comparators INPUT as ANALOG but technically their OUTPUT is DIGITAL since it can only be a High or a Low. RC4 is the OUTPUT for Comparator 2. If you are using Comparator 2, you DON'T want to set that pin to ANALOG (because ANALOG refers really only to INPUTS), but you want DIGITAL OUTPUT.

    Look at figures 8.2 & 8.3 in the Comparator Section. They show you the Comparator INPUT arrangement. For your convenience CxVin- has four possible sources.

    The 16F690 does NOT have a CSM Module.

    This means that if you want to play with capacitive sensing you have to configure the Comparators as an Oscillator yourself, the frequency of Oscillation will change when you place your Dabs on the Sensing Terminal. It is up to you to detect the change in frequency. So really any PIC with Comparators can do that. It's nice that the 16F690 has a quad input to each Comparator, which means that each Comparator can potentially service up to four capacitive buttons (NOT like your schematic in the first post which cannot differentiate which Button is being touched). That's the easy part.

    The Hard part comes when you discover that the frequency will SIGNIFICANTLY DRIFT with ambient TEMPERATURE and HUMIDITY. This means you have to continually sample and reset your base reference. Then some snotty kid comes along and presses your button with damp hands 'cos he's just been picking his nose, and your base reference swings wildly into the unknown. Enjoy...

    (that said, I'm surprised that there aren't many many more people chomping at the bit to get funky proximity touch sensor switches working on there PICs)
    Some of us have a life... *smiles*... (quite apart from the fact that a tactile PCB switch costs about 5 cents and is reliable. Mount it behind a flexible overlay and all you need is a pull-up Resistor and ONE LINE of code to see if anybody's pressed it or not. It doesn't care if the overlay is dry or wet or somewhere in between, and it doesn't care about the flavour of Ben & Jerry's you want to slap on it!).

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    I have implemented capacitive touch sensing using a PIC in a handheld terminal project. I needed the ability to sense up to 32 touch pads (and control a 128x64 pixel graphic LCD) and went with a different approach that did not require a PIC with a CSM module or comparators. I used an external oscillator (a CMOS version of the 555 operating at 2MHz) - this approach allows it to be implemented with any PIC (or other processor such as Atmel, MSP, etc. - I used a 44-pin PIC18F44K20 which controls everything). Works real well. Front and rear pics of the prototype below.


  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Hello Melanie,

    firstly, thank you as ever for the comprehensive reply (& avoiding an overpowering temptation to pour scorn!)

    Quote Originally Posted by Melanie View Post
    Going back to your first post...

    There is a difference... pin 18 is C12IN0- and pin 15 is C12IN1-

    This is taken from my Datasheet DS41262E (yours might be an extinct version).
    Yes, I had an old datasheet, hey ho!

    Quote Originally Posted by Melanie View Post
    Going back to your first post...

    You asked about RC4. Whether you consider a Comparator OUTPUT as analog I suppose is up to you. I consider Comparators INPUT as ANALOG but technically their OUTPUT is DIGITAL since it can only be a High or a Low. RC4 is the OUTPUT for Comparator 2. If you are using Comparator 2, you DON'T want to set that pin to ANALOG (because ANALOG refers really only to INPUTS), but you want DIGITAL OUTPUT.
    I have to say, this confuses me - as an old analoguey dinosaur (desperately trying to find his feet in the whacky world of digital), a comparator is analogue, but thinking about it more, an SR latch is digital. But that said, I've tried several permutations with digital and analogue pins! I'll revisit this in the light of your reply.

    Quote Originally Posted by Melanie View Post
    Look at figures 8.2 & 8.3 in the Comparator Section. They show you the Comparator INPUT arrangement. For your convenience CxVin- has four possible sources.

    The 16F690 does NOT have a CSM Module.
    Yes, this is one bit I understood...but nevertheless it does have a Comparator SR latch relaxation oscillator possibility ...which ought to work!

    Quote Originally Posted by Melanie View Post
    This means that if you want to play with capacitive sensing you have to configure the Comparators as an Oscillator yourself, the frequency of Oscillation will change when you place your Dabs on the Sensing Terminal. It is up to you to detect the change in frequency. So really any PIC with Comparators can do that. It's nice that the 16F690 has a quad input to each Comparator, which means that each Comparator can potentially service up to four capacitive buttons (NOT like your schematic in the first post which cannot differentiate which Button is being touched). That's the easy part.
    yes that part of the schematic was wrong (and was pretty much lifted from Microchip's application note .... http://ww1.microchip.com/downloads/e...tes/01101a.pdf Appendix B - it's wrong!)

    Quote Originally Posted by Melanie View Post
    The Hard part comes when you discover that the frequency will SIGNIFICANTLY DRIFT with ambient TEMPERATURE and HUMIDITY. This means you have to continually sample and reset your base reference. Then some snotty kid comes along and presses your button with damp hands 'cos he's just been picking his nose, and your base reference swings wildly into the unknown. Enjoy...
    yes I know about the drift....but if you believe the hype on the microchip site, it can be accounted for in code (I should have something ready for this aspect in a few years)

    Quote Originally Posted by Melanie View Post
    Some of us have a life... *smiles*... (quite apart from the fact that a tactile PCB switch costs about 5 cents and is reliable. Mount it behind a flexible overlay and all you need is a pull-up Resistor and ONE LINE of code to see if anybody's pressed it or not. It doesn't care if the overlay is dry or wet or somewhere in between, and it doesn't care about the flavour of Ben & Jerry's you want to slap on it!).
    ......and some of us have guitars, the real estate of which is more sacrosanct than the Turin shroud! :-) believe me, if I could justify a h/w switch I would just use that ...but taking a drill to my vintage guitar would be like violation. (far better to have a capacitive touch sensor located somewhere under the scratchplate)

    Thanks for your help though ...it really is appreciated . :-)
    Last edited by HankMcSpank; - 22nd November 2009 at 16:21.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If your Guitar is so sacrosanct, then why even consider sticking stuff to it? Leave it the way the manufacturer intended it to sound and why not simply build a bigger custom wah-wah pedal box with a heap more buttons and functions for controlling your effects?

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Ah... I see what I wrote with regard to DIGITAL OUTPUT... what I meant was that the COMPARATOR gives you the Digital Output. You NEED to select C1OE and C1ON (C2OE & C2ON) bits to 1 so the Comparator gives you a physical Hardware Output (rather than just setting a bit in a Register internally within the PIC), and you set the TRIS for that pin to 0 (treat it as DIGITAL OUTPUT - which is what it is).

  8. #8
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Hi HankMcSpank,

    Here's their simple schematic here (source = http://ww1.microchip.com/downloads/e...tes/01171B.pdf) ...
    The application note that you refered to in your first post is about a built-in capacitive sensing module in the PIC16F72x series. You are using something else, the 16F690. The capacitive sensors can be done with the 16F690, but that is the hard way. With the PIC16F72x series it is much simpler. You don't need comparators or any external components. I have built some of these capacitive switches for some of my projects and they work like a charm.

    Check out in this forum some posts by Byte_Butcher and myself about this touchsensors. We have already struggled to make these chips work but finally we got it.

    Just as a final note, by using an oscilloscope to see the signal changes you are adding a lot of capacitance to the line and this is no good when detecting capacitance from your fingers.

    Robert

  9. #9
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rsocor01 View Post
    Hi HankMcSpank,



    The application note that you refered to in your first post is about a built-in capacitive sensing module in the PIC16F72x series. You are using something else, the 16F690. The capacitive sensors can be done with the 16F690, but that is the hard way. With the PIC16F72x series it is much simpler. You don't need comparators or any external components. I have built some of these capacitive switches for some of my projects and they work like a charm.

    Check out in this forum some posts by Byte_Butcher and myself about this touchsensors. We have already struggled to make these chips work but finally we got it.

    Just as a final note, by using an oscilloscope to see the signal changes you are adding a lot of capacitance to the line and this is no good when detecting capacitance from your fingers.

    Robert
    All good points well made...I did get a bit carried away with my linkage above, but I'm basing most of this 16F690 stuff on http://ww1.microchip.com/downloads/e...tes/01101a.pdf ...which is using the same method I'm targetting here comparator+SR latch vs the capactive sense module). I do have a PIC16F726 winging it's way to me...but the extra piN count (ie bigger size), is not that welcome!

    Good point about the scope though...since we're talking picofarads, you're quite right...it's going to have a major impact on the results (but allow me to wallow for just a few minutes & enjoy those oscillations onscreen ...it's taken me two nights to see 'em!)

    Re byte_butcher's post - yep, it's a good 'un (tks Msr Butcher!), albeit he uses the CSM of the 16f72x series.

    I've actually already stumbled at the next hurdle of this embryonic second stage ...ie where I'm presently parachuting in bits of byte_butchers interupt code into mine. (plagiarism is alive and well)....

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

    I'm well out my depth here...so now off to get a scuba tank.
    Last edited by HankMcSpank; - 22nd November 2009 at 21:02.

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

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

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

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