multiple switches~one ADC


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Thanks mackrackit, IF (ADVAL > 1) AND (ADVAL < 53) THEN ... this code is working..
    Since we using ADCIN for switches, should be able to TOGGLE the ports.. I have tried with WHILE..WEND also.. no luck.. Could you pls ..Thanks again.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can we see your WHILE/WEND code? Or better yet your new and updated code.
    But something like this should work
    Code:
    ADCIN 0, adval
    WHILE (ADVAL > 1) AND (ADVAL < 53)
    do something
    ADCIN 0, adval
    WEND
    SELECT CASE ....
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Hi, The debounce was the problem..Following both codes are working after adding some delay.. I didnt use CASE.. Pls suggest if it needs to be fine tuned..Thanx..
    if (ADVAL > 200) AND (ADVAL < 256) THEN
    toggle porte.0
    pause 150
    endif
    -----------------------------------------------
    ADCIN 0, adval
    WHILE (ADVAL = 255) 'AND (ADVAL < 256)
    toggle porte.0
    pause 150
    ADCIN 0, adval
    WEND

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    If it is all working then I would say it is good.
    not knowing yhe whole project it is hard to say if it needs fine tuned, but what you have looks like a good solution.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    If it is all working then I would say it is good.
    not knowing yhe whole project it is hard to say if it needs fine tuned, but what you have looks like a good solution.
    Thanks..Shall post the complete project shortly..

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Hi Naga. I did something like this before. I edited the code & schematic to show only the relevent info. The only thing different is if you press the bottom 2 switches at the same time, it will do a 5th function.

    ANSEL = 0 'all inputs digital ADC command converts to analog
    CMCON = 7 'comparators off
    DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device
    @ device pic12F675, INTRC_OSC_NOCLKOUT, wdt_on, BOD_ON, pwrt_on, mclr_off, protect_on
    BUT VAR BYTE 'MESSAGE BUTTONS VARIABLE
    BUT2 VAR BYTE 'VARIABLE TO COMPARE BUT READINGS TO PREVENT WRONG ADC READINGS

    Pause 500 'SETTLE DOWN

    START:
    NAP 0 'REDUCE STANDBY CURRENT
    ADCIN 3,BUT
    IF BUT < 100 Then TABLE 'BUTTON PUSHED
    GoTo START

    TABLE:
    ADCIN 3,BUT
    Pause 100
    ADCIN 3,BUT2
    IF BUT <> BUT2 Then TABLE 'RE-READ THE ADC

    IF BUT < 91 AND BUT > 71 Then (DO 1ST THING)
    IF BUT < 50 AND BUT > 40 Then (DO 2ND THING)
    IF BUT < 15 AND BUT > 8 Then (DO 3RD THING)
    IF BUT < 8 AND BUT > 4 Then (DO 4TH THING)
    IF BUT < 5 AND BUT > 2 Then (DO 5TH THING)
    GOTO START
    Attached Images Attached Images

  7. #7
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    @ Peterdeco1,Thank you very much .. Very nice..Working perfectly.. Thanks to all of you..
    Other problem is..
    When using MeLabs default (PM) Assembler compiles OK:
    @ device pic12F675, INTRC_OSC_NOCLKOUT, wdt_on, BOD_ON, pwrt_on, mclr_off, protect_on

    When using Microchip's (MPASM) Assembler:

    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    3 errors,image attached..
    Attached Images Attached Images  
    Last edited by naga; - 18th August 2009 at 07:45.

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. multiple ADC using DSpic 30f3010
    By angeline in forum mel PIC BASIC
    Replies: 6
    Last Post: - 22nd February 2008, 10:03
  3. 18F1320 ADC multiple channel select
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2005, 21:40
  4. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 16:46
  5. Reading multiple ADC channels FAST
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st April 2004, 22:37

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