my project Capacitive Sensing LED dimmer 12F1822 via PWM


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: my project Capacitive Sensing LED dimmer 12F1822 via PWM

    Just wondering if anybody has taken the time to bread board up the circuit and see how it works?

    If you do build the circuit I suggest you lower the value of the Resistor in the Zener ckt to around 4700 ohms.
    (Assuming you are trying to drive it with 12 Volts)


    I still need to learn about how to best design a small circuit board with an included touch pad. I still am unsure if I need a surrounding ground to make the touch sense work better.

    My testing shows that it does not seem to make much difference.


    Here is a link to a video of my circuit working

    (the video is in my drop box so I am not sure how this will work, its about 8 meg)

    https://dl.dropboxusercontent.com/u/...LED_dimmer.m4v
    Last edited by Heckler; - 4th December 2013 at 04:18.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: my project Capacitive Sensing LED dimmer 12F1822 via PWM

    Hi Dwight,

    Are you looking to make these Camping/Emergency lights as a commercial venture or just for your own use?
    If it is the latter, you would probably be best served (from a purist aspect) to throw a bit more coin at an LDO voltage regulator.

    From my own curiosity standpoint, what have you used for the capacitive touch sensor in your prototype and how do you plan to implement the sensor in your production unit?

    Cheers
    Barry
    VK2XBP

  3. #3
    Join Date
    Apr 2016
    Location
    Mi, USA
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: my project Capacitive Sensing LED dimmer 12F1822 via PWM

    Hello!
    I'm new here, but I like your capacitive touch program example. The only difference I would like to be able to do is have 3 touch pads, one for brightness up, brightness down, and one for on/off. I just wonder where
    I would put the code that would scan the three cps inputs, would it be in the main program area, or in the interrupt itself? I'm also driving 5 leds that indicate what brightness I am at. Currently, I have the scan code in the main program area, and the determination of which switch is pressed in the interrupt portion. However, I keep having problems with the touch working intermittently. Can you see where I am having problems?
    I am using a PIC16LF722A for the micro.


    '************************************************* ***************
    '* Notes : Copyright (c) 2016 *
    '* : Editor MicroCode Studio Plus PBP 3.0.6.0 *
    '* : LS1236-A Startrol Touch Controller *
    '* : MUST BUILD PROJECT WITH MPASM ASSEMBLER *
    '* : Device = 16LF722A-I/SO *
    '* Version : 1y.0 *
    '* Name : LS1236_1y.BAS *
    '* Author : R. WRIGHT *
    '* : *
    '************************************************* ***************

    'SET CONFIGURATION FOR INTERNAL OSCILLATOR WITH PLL MULTIPLIER ON
    #CONFIG
    __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDTE_OFF & _BOR_OFF & _PLLEN_ON
    #ENDCONFIG


    define OSC 4


    INCLUDE "DT_INTS-14.bas" ' PBP interrupt routines (MUST BE IN SAME FOLDER)
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    ' Courtesy of Derryl Taylor, PBP Wizard!

    OSCCON = %00010000 'SETS INT OSC TO 4Mhz
    ANSELB = %00000111 'SETS INPUTS B0-B2 AS ANALOG
    TRISB = %00000111 'SETS INPUTS B0-B2 AS INPUTS
    WPUB = %00000000 'DISABLES WEAK PULL-UP BITS
    'TRISC = %00001000 'SETS INPUT C3 AS INPUT

    OPTION_REG = %10000111
    '1 = All weak pull-ups are disabled (except MCLR, if it is enabled)
    ' 0 = Interrupt on falling edge of RB0/INT pin
    ' 0 = Timer0 clock is internal cycle clock (Fosc/4)
    ' 0 = Increment on low-to-high transition on RA4/T0CKI pin
    ' 0 = Prescaler is assigned to the Timer0 module
    ' 111 = 1:256 Timer0 prescaler rate

    T1CON = %11000001 'enable timer 1 (bit 0) & source the clock from the CPS module (bit 6 & 7 =11)
    'set the CPS module highest frequency availabe (for vcc mode) + timer0 clock sourced from CPS module. (BIT 1)


    CPSCON0 = %10001100 '1 = CPS module is enabled
    ' 000 = unused
    ' 11 = Oscillator is in High Range. Charge/Discharge Current is nominally 18 µA
    ' 0 = Capacitive Sensing Oscillator Status bit (only readable)
    ' 0 = Timer0 clock source is controlled by the core/Timer0 module and is FOSC/4

    CPSCON1 = %00000001 '0001 = channel 1, (CPS1)


    ' Software variables

    CPSX_PRESENT var WORD 'VARIABLE FOR BUTTON CURRENT VALUE
    CPSX_THRESHOLD var WORD 'VARIABLE FOR BUTTON THRESHOLD VALUE
    CPSX_LAST var WORD 'VARIABLE FOR PREVIOUS BUTTON VALUE
    Duty VAR WORD 'VARIABLE FOR DUTY CYCLE
    stepp var byte 'VARIABLE FOR BRIGHTNESS LEVEL
    incnt var byte 'BUTTON PUSH INCRIMENT
    LOCLEV VAR BYTE 'LOCAL MODULE BRIGHTNESS LEVEL
    REMLEV VAR BYTE 'REMOTE MODULE BRIGHTNESS LEVEL
    IOTOG VAR BIT 'TOGGLE BIT FOR I/O BUTTON

    ' variables used by interrupt handler, comment out as per assembler
    wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
    'wsave VAR BYTE $70 SYSTEM ' alternate save location for W
    ' if using $70, comment wsave1-3

    ' --- IF any of these three lines cause an error ?? ------------------------
    ' Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using --
    wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
    'wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
    'wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3





    ' SET DEVICE I/O PINS


    LED1 VAR PORTA.1 ' SET LED LEVEL INDICATORS
    LED2 VAR PORTA.2
    LED3 VAR PORTA.3
    LED4 VAR PORTA.4
    LED5 VAR PORTA.5


    ' Software/Hardware initialization

    PAUSE 50 ' OSC settle delay
    Duty = 255 ' SET INITIAL BRIGHTNESS TO FULL ON
    stepp = 5 ' SET INITIAL LOOKUP TABLE TO 5
    incnt = 1 ' set input counter to input 1
    iotog = 1 ' SET I/O BUTTON TOGGLE TO high
    hpwm 1,DUTY,1000 ' INITIALIZE HARDWARE PWM TO SELECTED LEVELS
    HIGH LED5 ' TURN ON OUTPUT FOR LED 5
    pause 1000 ' LET EVERYTHING SETTLE

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR0_INT, _Timer0_Int, pbp, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    TMR0 = 0 'clear TIMER0
    @ INT_ENABLE TMR0_INT 'enable timer0 interrupts
    PAUSE 100


    '************************************************* **********************
    '------------------------------< Main program >-------------------------

    'SCAN INPUTS UNTIL FINGER DEPRESSION IS DETECTED
    Main:

    incnt = 2
    cpscon1 = %00000001 ' 0001 = channel 1, (CPS1), DOWN BUTTON
    ANSELB = %00000010 ' SETS INPUT B1 AS ANALOG
    TRISB = %00000010 ' SETS INPUTS B1 AS INPUTS
    PAUSE 100
    INcnt = 3
    cpscon1 = %00000010 ' 0010 = channel 2, (CPS2), UP BUTTON
    ANSELB = %00000100 ' SETS INPUT B2 AS ANALOG
    TRISB = %00000100 ' SETS INPUT B2 AS INPUT
    PAuse 100
    incnt = 1
    cpscon1 = %00000000 ' 0000 = channel 0, (CPS0), 1/0 BUTTON
    ANSELB = %00000001 ' SETS INPUT B0 AS ANALOG
    TRISB = %00000001 ' SETS INPUT B0 AS INPUT
    Pause 100 ' WAIT FOR INTERRUPT

    Goto Main

    '************************************************* ****************************
    Timer0_Int:
    @ INT_DISABLE TMR0_INT ; stop timer0 interrupts while we're in here
    pause 100

    ' store away the present timer0 count for the next time we come into the interrupt routine
    CPSX_PRESENT = TMR1 ' take a snapshot of Timer1's present count.
    CPSX_THRESHOLD = CPSX_PRESENT - ((CPSX_LAST/10)*5) ' this sets the 'trigger' up for a 50% diversion (finger press)
    CPSX_LAST = CPSX_PRESENT

    'DETERMINES WHICH BUTTON HAS BEEN PRESSED
    IF CPSX_PRESENT < CPSX_THRESHOLD THEN
    if (incnt = 3) AND (STEPP > 1) then ' down button pressed so decriment stepp
    stepp = stepp - 1
    GOTO SKIP1
    ENDIF
    If (incnt = 2) AND (STEPP < 5) then ' up button pressed so incriment stepp
    stepp = stepp + 1
    GOTO SKIP1
    endif
    IF (INCNT = 1) AND (iotog = 0) THEN ' 1/0 button pressed for off
    STEPP = 0
    IOTOG = 1
    GOTO SKIP1
    ENDIF
    IF (INCNT = 1) AND (iotog = 1) THEN ' 1/0 button pressed for on
    STEPP = 5
    IOTOG = 0
    ENDIF


    ' lights appropriate leds according to the current lookup table value
    SKIP1:
    IF STEPP = 5 THEN
    HIGH LED5
    ENDIF
    IF STEPP = 4 THEN
    HIGH LED4
    ENDIF
    IF STEPP = 3 THEN
    HIGH LED3
    ENDIF
    IF STEPP = 2 THEN
    HIGH LED2
    ENDIF
    IF STEPP = 1 THEN
    HIGH LED1
    ENDIF
    if stepp = 0 THEN
    LOW LED1
    endif



    ' SETS HARDWARE PWM OUTPUT 1 TO DESIRED LEVEL
    lookup stepp, [0,16,32,64,128,255],duty ' choose level, 5 levels plus OFF
    hpwm 1,duty,1000 ' set new level
    ' pause 100

    ENDIF


    pause 100
    TMR0 = 0 ' clear TIMER0
    TMR1 = 0 ' clear TIMER1
    @ INT_ENABLE TMR0_INT ; re-enable timer0 interrupt
    @ INT_RETURN

    resume

Similar Threads

  1. 16F726 Capacitive sensing module
    By Byte_Butcher in forum General
    Replies: 39
    Last Post: - 15th May 2014, 19:40
  2. Need help setting up Capacitive Sense 12F1822
    By Heckler in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th November 2013, 21:10
  3. Replies: 1
    Last Post: - 6th August 2012, 10:57
  4. Capacitive sensing module on 16f1936
    By grahamg in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 25th April 2010, 14:17
  5. mTouch capacitive sensing
    By jrprogrammer in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 1st November 2008, 22:54

Members who have read this thread : 1

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