1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

input and save input

Discussion in 'Microcontrollers' started by MrDEB, Nov 7, 2017.

  1. tumbleweed

    tumbleweed Active Member

    Joined:
    Jan 25, 2007
    Messages:
    135
    Likes:
    36
    ARGHHHHHHHHHHHHHH!


    ADC.Read(0) reads the ADC and returns the unmodified reading. Use that, exactly as shown. Don't call another function. Don't convert it to volts. Don't add 1. Don't multiply or divide it by anything.


    Just use the code in post #177, which is the one Burt copied from. (I'd suggest Mike's method, but that one's bound to get us another 40 pages)
     
    • Like Like x 1
  2. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    I didn't post nothing that give a result in volts
    I just fixed his messed up function
    To return just the ADC value.
     
  3. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    Dear god
    I took the function fixed it to work with the case statement

    Code (text):

    function ADInAsVolt() as word
       result = ADC.Read(0)
    end function
    Select ADInAsVolt()
         Case <25
               'no button pressed
         Case <100       ' ideal=92
               'button 1 pressed
         Case <200       ' ideal=185
               'button 2 pressed
         Case <300       'ideal=278
               'button 3 pressed
         Case <400       'ideal=371
               'button 4 pressed
         Case <500       'ideal=464
               'button 5 pressed
         Case <600       'ideal=557
               'button 6 pressed
         Case <700       'ideal=650
               'button 7 pressed
         Case <800       'ideal=743
               'button 8 pressed
         Case <900       'ideal=836
               'button 9 pressed
         Case <1000       'ideal=929
               'button 10 pressed
         else
               'something is wrong
    End Select
    Right this is not needed but it would have one in his code doing the wrong thing so I made him one that works
    Code (text):

    function ADInAsVolt() as word
       result = ADC.Read(0)
    end function
     
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  5. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    Jon that's not true All Did was fix the function he had and make it just return adc reading
    and showed how to use it with a case statement that has been posted
     
  6. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,637
    Likes:
    145
    Location:
    Seattle, WA
    The ADCInAsVolts is the wrong function isn't it? From the ADC documentation, Read(ANo) should be all that's needed.
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    Ok Mrdeb copied from swordfish the function that scales to voltage I removed the math and fixed that. Nothing wrong with that but a renaming of a function

    Now as for this all he really needs is to call adc.read(0) and test with the case
    But both will work one posted by someone and fixing his XXXXup function
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  9. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,637
    Likes:
    145
    Location:
    Seattle, WA
    Sorry Burt, you are right. I didn't notice you removed all the math from the ADCasVolts function. But calling it that just confuses the issue. It doesn't give you volts and you don't want volts...and for some one who doesn't pay attention to details or understand how things work, it's going to add to the confusion. Besides,

    ADC.Read(An0) is pretty fricken' clear and easy.

    I would add the ADC prefix as many modules have a read command. The prefix insures you get the right one.
     
  10. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    Jon I just redid his function cause no mater what we say it will have one. Only reason his was not working is because he was changing the reading with the math.

    And I posted it with the case statement with one change that would make them work together.

    But like you say
     
  11. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,595
    Likes:
    25
    I tried every suggestion and this code almost works right. Needs some tweeking at led7 etc.
    Tried Burts last suggestion and no where near without putting the 500/1024 in the code.
    Mikes suggestion of 1024/10 etc. got me close. It isn't as kosher or correct concerning the resistor ladder and having the correct ratios
     
  12. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,595
    Likes:
    25
    I rearranged the resistor ladder by taking out the 100K/ .1 cap, and connecting the port A0 to the switches. The circuit works but needs some tweeking on the lower readings. Led 4-10 work just fine. Will figure out why etc and post results.
     
  13. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,637
    Likes:
    145
    Location:
    Seattle, WA
    I am so glad I've put so much effort into explaining things only to have it all ignored.

    MrDEB, keep up with your copy&paste programming. There really is no need to actually understand anything...why do something in 10 minutes when you can get people to waste so much time with over 200 posts in a forum thread.

    Let's be conservative and say each post is 10 minutes of effort. 2000 minutes is over 30 wasted hours of people's time, all for the joy of helping you.
     
  14. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    See l did one that he should of used back to his bad function
     
  15. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,637
    Likes:
    145
    Location:
    Seattle, WA
    Not quite...he's not multiplying by 5. He's multiplying by 500/1024 for no apparent reason.

    He forgot to multiply by 2017....I mean 2018 as of last night....and divide by 10 pages of forum replies.
     
    • Like Like x 1
  16. JimB

    JimB Super Moderator Most Helpful Member

    Joined:
    Sep 11, 2004
    Messages:
    6,699
    Likes:
    650
    Location:
    Peterhead, Scotland
    ONLINE
    I have been reading this thread for a few days now, it is like one of those really bad films that they sometimes (often?) show on television.
    You start watching it, decide it is bad, but you cannot leave it, it is so bad that you just have to keep watching, there has to be a good bit coming up soon, but there never is.


    To supplement the efforts of JonSea and be80be and to try in my own way to summarise what they have been saying, I offer the following few words:

    1 Connect a bunch of resistors to make a potential divider.
    2 Connect the junctions of the resistors to push button switches.
    3 Connect the "common" of the switches to an analog input on a PIC micro.

    4 Before writing any code, test the hardware.
    4a Apply power.
    4b Press the switches, one at a time.
    4c Use a DMM and measure the voltage at the PIC input pin.
    4d Write down the results.
    4e Look at the results, are the voltages sensible? Do they step up/down as per the button pushes? Do they correspond to the values calculated in the design process?
    4f If all is well, move to step 5. If all is not well, debug the hardware.

    5 Write some code:
    5a Initialise the PIC, pay special attention to the ADC.
    5b Read the ADC, and display the ADC result on an LCD display.
    (Note here that the result from the ADC is just a number in the range 0 to 1023. Don't mess about trying to convert it to a voltage, just display the raw ADC value).

    6 Now test to code:
    6a Apply power.
    6b Press the switches, one at a time.
    6c Read the numbers from the LCD.
    6d Write down the results.
    6e Look at the results, are the numbers sensible? Do they step up/down as per the button pushes? Do they correspond to the values calculated in the design process?
    6f If all is well, move on and develop the CASE statement. If all is not well, debug the simple bit of code which you just wrote.

    It is not that difficult.

    JimB
     
  17. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,637
    Likes:
    145
    Location:
    Seattle, WA
    MrDEB either has a really good imagination (or loose grasp on reality), or he's just putting us on.

    In his posted code, he has the command

    SetAllDigital

    which not surprisingly, sets all of the ADC inputs to digital I/O. I don't believe the ADC module does anything to override this because, as I explained previously, the Swordfish example file includes code to set up the analog input.

    SmartSelectImage_2018-01-02-00-35-56.png

    The Input(PortA.0] should take care of the Tris command, but without the next line, PortA.0 is a digital input because of the SetAllDigital command.

    Help is happy given to those who make an effort to understand the replies, and whose next posts show a grasp of what's been explained. MrDEB can't explain why he decided to reinsert 500/1024 other than he saw it somewhere and he completely failed to understand what had been explained by at least 3 people. Sigh.
     
  18. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    What the hell is this has to be a joke.
    Code (text):

    SELECT position
    CASE <25 Player10 = false led10=1 DELAYMS(1000) led10=0 DELAYMS(1000)// No player

    CASE <51 Player11 = true Led0=1 DELAYMS(1000) Led0=0 DELAYMS(1000)

    CASE <153 Player1 = true Led1=1 DELAYMS(1000) Led1=0 DELAYMS(1000)

    CASE <204 Player2 = true Led2=1 DELAYMS(1000) Led2=0 DELAYMS(1000)

    CASE <255 Player3 = true Led3=1 DELAYMS(1000) Led3=0 DELAYMS(1000)

    CASE <308 Player4 = true Led4=1 DELAYMS(1000) Led4=0 DELAYMS(1000)

    CASE <355 Player5 = true Led5=1 DELAYMS(1000) Led5=0 DELAYMS(1000)

    CASE <460 Player6 = true Led6=1 DELAYMS(1000) Led6=0 DELAYMS(1000)

    CASE <500 Player7 = true Led7=1 DELAYMS(1000) Led7=0 DELAYMS(1000)

    CASE <535 Player8 = true Led8=1 DELAYMS(500) Led8=0 DELAYMS(500)

    CASE >1000 Player9 = true Led9=1 DELAYMS(1000) Led9=0 DELAYMS(1000)
    END SELECT // need to indicate when player pos is done
     
    The lowest case would be 44 the highest would be about 500
    but why do it like that no wonder your getting nothing like has been posted.
     
    Last edited: Jan 2, 2018
  19. tumbleweed

    tumbleweed Active Member

    Joined:
    Jan 25, 2007
    Messages:
    135
    Likes:
    36
    JimB -

    You forgot the all important Step #7....

    7 Ignore steps 1-6 and insert random code/hardware changes until "it works". Be sure to avoid ANY and ALL suggestions made by others. Most importantly, make sure you have no idea what any of the code you copy is doing (otherwise it might accidentally work, and we'll have none of that!).
     
    • Agree Agree x 2
    • Like Like x 1
  20. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,595
    Likes:
    25
    Jon may have the reason why this circuit is not doing what it is supposed to do (see post #215)
    will try this out
     
  21. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,595
    Likes:
    25
    Well I think Jon may have hit on the solution (see post #215)
    As for the FUNCTION I tried with and without the +1 *500/1023 and both work the same or that's what it appears.
    I need to jingle the higher CASE SELECT numbers as they are slightly off. Probably due to resistor tolerances etc. but it appears to work.
    Now just waiting for switches and solder up this circuit using switches instead of an alligator clip.
     
  22. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,637
    Likes:
    145
    Location:
    Seattle, WA
    Do you really not understand ANYTHING about programmimg????

    How on Earth can it work the same with or without "*500/1024"? Multiplying by 500 and dividing by 1024 means with this, the value read is only half what it is without it. It works the same either way? Then it's NOT WORKING AT ALL

    AND WHEN YOU SAY "JON HIT THE NAIL ON THE HEAD" BY ENABLING THE ADC? WHAT IN THE HELL HAVE YOU BEEN DOING? YOU CAN'T HAVE GOTTEN ANY RESULTS THAT MAKE SENSE IN THE LEAST!!!!!!!!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice