Continue to Site

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.

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

input and save input

Status
Not open for further replies.
This was the email I opened immediately after leaving here. Seems appropriate.
20180104_073453.jpg
 
I read every single post.
See if my thinking is correct. The ADC.read(9) outputs a 10 bit number (0-1024)
using Mikes suggestion, 1024/10 = 102. 1024/20 = 51 for no key pressed. Add 102 + 52 = 154 for first key pressed. Add 102+154 = 256 for second key press etc. This is basically what needs to be computed.
Going to solder this circuit to a perf-board with the 10 switches and add the extra circuitry as code progresses. Found writing code in snippets then combining all seems to work better.
Now just to procure some perf-board.
I was attempting to try >52 <256 for first key but it doesn't work. A larger window for the SELECT CASE.
 
What mike said would work if you do as mike said But you said your not getting even reading which you should be.

Add 102 + 52 = 154 is not what he said
 
post #131 is what I am referring to.
Am trying the usart approach but only getting 1 reading regardless what "button" is pressed.
Need to re-access what the uart is doing and looking at using the software uart but not until I figure out why it is not working right.
 
I would use this
Code:
Select ADC.read(0)
     Case <50
           'no button pressed
     Case <150       ' ideal=92
           'button 1 pressed
     Case <250       ' ideal=185
           'button 2 pressed
     Case <350       'ideal=278
           'button 3 pressed
     Case <450       'ideal=371
           'button 4 pressed
     Case <550       'ideal=464
           'button 5 pressed
     Case <650       'ideal=557
           'button 6 pressed
     Case <750       'ideal=650
           'button 7 pressed
     Case <850       'ideal=743
           'button 8 pressed
     Case <950       'ideal=836
           'button 9 pressed
     Case <1050       'ideal=929
           'button 10 pressed
     else
           'something is wrong
End Select
The meter is where you take reading and if you do it like shown it will work
Screenshot from 2018-01-05 09-51-22.png
 
Try it I put a delay so it don't spit out so fast you have to change that if you use it in your code
Code:
Device = 18f2420
Clock = 8
Include "InternalOscillator.bas" 
Include "SetDigitalIO.bas"
Include "adc.bas"
Include "Utils.bas"
Include "SUART.bas"
Include "convert.bas"
SetTX(PORTC.6)
SetRX(PORTC.7)
SetBaudrate(sbr19200)
SetMode(umTrue)
ADCON1 = $07
CMCON = $07     
TRISA.0 = 1        // configure AN0 as an input 
ADCON1.7 = 1       // set analogue input on PORTA.0 
While true
Select ADC.Read(0)
     Case <50
           UART.Write("No button",13,10)'no button pressed
           DelayMS (200)
     Case <150       ' ideal=92
          UART.Write("button1",13,10) 'button 1 pressed
          DelayMS (200)
     Case <250       ' ideal=185
          UART.Write("button2",13,10) 'button 2 pressed
          DelayMS (200)
     Case <350       'ideal=278
          UART.Write("button3",13,10) 'button 3 pressed
          DelayMS (200)
     Case <450       'ideal=371
          UART.Write("button4",13,10) 'button 4 pressed
          DelayMS (200)
     Case <550       'ideal=464
          UART.Write("button5",13,10)'button 5 pressed
          DelayMS (200)
     Case <650       'ideal=557
          UART.Write("button6",13,10) 'button 6 pressed
          DelayMS (200)
     Case <750       'ideal=650
          UART.Write("button7",13,10) 'button 7 pressed
          DelayMS (200)
     Case <850       'ideal=743
          UART.Write("button8",13,10) 'button 8 pressed
          DelayMS (200)
     Case <950       'ideal=836
          UART.Write("button9",13,10) 'button 9 pressed
          DelayMS (200)
     Case <1050       'ideal=929
          UART.Write("button10",13,10) 'button 10 pressed
          DelayMS (200)
     Else
           'something is wrong
End Select
Wend
 
Am using the circuit in post #126 (has 2K resistor to grd. but will try without the extra 2K resistor
Thanks
 
Thanks. It is close but the uart shows what button instead of having to count which LED is enabled.
I need to tweek the numbers a little as it jumps from #2 to #4 and two #7's
just some tweeking. Hopefully after I get some perf-board and solder a board together I can eliminate erratic outputs etc.
 
That's with Mikes figures don't work with Jons post 126
mike said 10 resistors total of 10 k jon has 12 k that changes the math
you can get the raw adc value for each press
with this
Code:
Device = 18f2420
Clock = 8
Include "InternalOscillator.bas"
Include "SetDigitalIO.bas"
Include "adc.bas"
Include "Utils.bas"
Include "SUART.bas"
Include "convert.bas"
DIM value AS WORD
SetTX(PORTC.6)
SetRX(PORTC.7)
SetBaudrate(sbr19200)
SetMode(umTrue)
ADCON1 = $07
CMCON = $07   
TRISA.0 = 1        // configure AN0 as an input
ADCON1.7 = 1       // set analogue input on PORTA.0
While true
value = ADC.Read(0)
UART.Write(value,13,10)
DelayMS (200)
wend
Like I said before there is a delay to slow down the uart from spitting out to fast this will give you a adc value to see why your off from what I posted
but the uart shows what button instead
It can't send what ever you want.
players phone number wifes name or the adc value LOL
 
Last edited:
something not right?
I had compile error and edited the vaiue to value but all it displays are ??????????? sometime a small rectangle next to the ?
Wife has an appointment so get back to later.
 
Why don't you just have a little loop that squirts out the ADC values continuously while you figure it out. I must be really smart or....nevermind.

(No button pressed)
0
0
0
0
0
(button 1 pressed)
39
39
39
39
(Button 1 released)
0
0
0
0
(Button 2 pressed)
84
84
84
84
84
(Button 2 released)
0
0
0
0

etc.

See if the #%=& hardware works right and gives results close to what's shown here (i.e., approximately uniform steps, in order overing the range of the ADC)....then work on the software. Like rational people do.
 
has 2K resistor to grd. but will try without the extra 2K resistor
10 damn pages of simulations and example code showing equal 1K resistors and you continue to use whatever you feel like.

Why do you ask questions and then continuously change things? Do you EVER implement what someone suggests EXACTLY as they suggest it?
If you do that and get different results then come back and ask questions to figure out why.

It's really very simple. Quit randomly changing things. The 1000 monkeys should be done soon...
 
I sincerely admire the patience of Jon, Burt, Mike and others who step in to help on these 'projects'.
It's like driving past a really bad accident scene and observing the efforts of the first responders - you know they're battling hard against the odds, but they will not give up.
 
19200 that's not 9600 sounds like your problems I fixed the i in value sorry I was just helping you out

I cant see as good as I did 10 years ago
 
News update: the monkeys have finished their board layout and sent it for fab.
 
If he uses the layout on post #126 it not going to read like Mike said
If he uses 10 1k resistors and ties the adc to ground with 100k and .1uf code I posted works fine anything else happens maybe im not the only one who can't see now days.
 
If he would read the dang actual values he gets from the ADC using serial output and leave out the BS math (which he still doesn't understand), then it wouldn't matter how screwed up his circuit is.
 
I am implementing the uart as recommended. I presently have only 10 resistors.
I am using the code suggestion that Burt posted but something is outta sorts and I am working on a fix usually in the mornings.
I have tried every single suggestion, understand the resistor ladder principle and am attempting to get the uart to correctly display the button pressed. Burt suggested viewing the ADC values, that's where the hangup is presently. Another issue is using a breadboard, a tap28, 10 resistors soldered together and hanging off the side of the breadboard and using an alligator clip to simulate button presses.
And no I have removed the math equations as well. Am using the code that was suggested.
 
yes I think I do
the 1024 is the 10 bit number the ADC reads.
the 500 is the 5 volts integer value. the + 1 ??
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top