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.
A little story. Many years ago I was using the ADC to read a pot. All the readings I got were skewed towards zero!! It didn't make sense. I eventually found that, although I'd switched to analogue, I'd left it as output and the chip itself was trying to drive the pin low. Lesson learnt, analogue pins can still be set to output and act as digital output pins. Just a wild guess.

Burt, maybe you could try this.

Mike.
 
TRISA = %00000001 set's as input
ADC.SetConfig($0E) set's the adc to use the AN0

Don't see I missed anything plus the code I posted works
This is what I posted
Code:
Device = 18F4520
Clock = 20
Include "adc.bas"
Include "Utils.bas"
Include "usart.bas"
Include "convert.bas"
Dim value As Word
#option USART_BRGH = True
Function ADC_value() As Word
  
        result = ADC.Read(0)    
End Function
TRISA = %00000001
ADC.SetConfig($0E)      // set ADCON1 for AN0 analog, rest digital
SetBaudrate(br9600)
While true
    DelayMS(20)
     value = ADC_value
       USART.Write(DecToStr(value),13,10)
        DelayMS(200)
Wend
 
Last edited:
Burt,

I didn't expect you to have missed anything. However, MrDebs results are skewed towards zero - maybe (I know it's not very likely) he missed something.

Mike.
 
This worked frist time
Code:
Device = 18F4520
Clock = 20
Include "adc.bas"
Include "Utils.bas"
Include "usart.bas"
Include "convert.bas"
Dim value As Word
#option USART_BRGH = True 
TRISA = %00000001
ADC.SetConfig($0E)      // set ADCON1 for AN0 analog, rest digital
SetBaudrate(br9600)
While true
Select ADC.Read(0)
     Case <50
           Write("No button",13,10)'no button pressed
           DelayMS (200)
     Case <150       ' ideal=92
          Write("button1",13,10) 'button 1 pressed
          DelayMS (200)
     Case <250       ' ideal=185
          Write("button2",13,10) 'button 2 pressed
          DelayMS (200)
     Case <350       'ideal=278
          Write("button3",13,10) 'button 3 pressed
          DelayMS (200)
     Case <450       'ideal=371
          Write("button4",13,10) 'button 4 pressed
          DelayMS (200)
     Case <550       'ideal=464
          Write("button5",13,10)'button 5 pressed
          DelayMS (200)
     Case <650       'ideal=557
          Write("button6",13,10) 'button 6 pressed
          DelayMS (200)
     Case <750       'ideal=650
          Write("button7",13,10) 'button 7 pressed
          DelayMS (200)
     Case <850       'ideal=743
          Write("button8",13,10) 'button 8 pressed
          DelayMS (200)
     Case <950       'ideal=836
          Write("button9",13,10) 'button 9 pressed
          DelayMS (200)
     Case <1050       'ideal=929
          Write("button10",13,10) 'button 10 pressed
          DelayMS (200)
     Else
           'something is wrong
End Select
DelayMS (1000)
Wend
 
Can you try setting the ADC pin to output and see if you get figures similar to MrDeb.

Mike.
 
Burt,

I didn't expect you to have missed anything. However, MrDebs results are skewed towards zero - maybe (I know it's not very likely) he missed something.

Mike.
Sorry I been working night's
I broke down and tried this out the latest swordfish has changes to the adc.bas and some file mismatch because of the way the adc pins are mapped on some chip's
Some you can use whatever pin you want and some you have to start from AN0 and if you wanted AN3 that means you set 4 of them as ADC.
I was playing with USB and the chip I tested with has 13 ADC pin's swordfish was only letting me use 5 of them and that didn't work cause I was using AN0
which was not one of the five.LOL
 
Can you try setting the ADC pin to output and see if you get figures similar to MrDeb.

Mike.
You get a 0
This is button code first try using your 10 resistors
and the 102 set about half way above I used 100 for each step plus 50
so 150 250 so on. worked out of the box.
 
Last edited:
Are you telling me that when you press the top button and put 5V on the pin it reads zero and not around 500 as MrDeb got?

Mike.
 
I got 0 and around 250 if the pin was not set to input it may go to 500 it was like it picking up noise
 
I am not going to use volts. That code using the FUNCTION was only for determining what the SELECT CASE data is close to.
Am off to raining S cal.
 
When I get back home I am going to wire up the circuit on a perf board with actual switches thus eliminating any circuit issues or at least eliminate having the ladder hanging off the side of the breadboard. The 511 output appears about half way.between ground and vcc. Something not right.
With all the issues concerning the ADC (battery life, pcb space etc.) I have not ruled out going with a 44+ pin smt chip.
Soldering them small pins by hand gives me second thoughts. Using a hot plate but the solder has a short shelf life.
I even considered using a 40 pin dip, flatten out the pins and end up with a bush-fix smd chip. Using a 44+ pin chip would maybe make life easier seeing how we are on page 15 concerning a simple ADC/ pic project.
I myself have learned a few things along the way.
 
PROJECT UPDATE
waiting on perf-boards to assemble a proto-type assembly then get down to actually programming this project. While visiting Calif. I wrote some code that should work but all bets are off.
I laid out a pcboard based on my schematic and realized a SOIC chip is basically too big for my layout with the 10cm x 10cm board, battery pack, leds and switches etc, the 44 pin QFN 18f46K20 is what I have settled on and less issues with ADC etc.
Decided to go with thirteen switches, 16 Leds and using the HLVD feature on the pic. Switches are ON/OFF, GAME SELECT AND ET TIME SELECT. and caN't forget the ICSP smd port.
LOTS of pcboard area being used and able to get desired layout for ease of players.
Plan to wait for protype to be usable THEN order boards.
 
Oh good. so 10 pages of this thread were for nothing.

Why are you putting the battery pack on the board?
 
The perf board is for assembling a proto-type circuit the make any needed changes to design. I plan to solder a resistor ladder to board as well since I want to get a better picture of how the suggested ADC code etc/ works. I haven't written off the idea, just putting it on the back burner.
 
Maybe MrDEB should use this part from TI.

Seriously, not a part for MrDEB as the data sheet is 94 pages, but it is an interesting part. 24 switches which may be high or low active plus an ADC to handle several of what the call analog coded switches, which in the automotive world csn be multi-speed switches for wimdshield wipers and heater fan controls. You still have to supply the ADC values of the switch points but it relieves the micro of the ADC task and determining which step is selected.

SmartSelectImage_2018-01-26-16-08-09.png
 
You posted a picture that will never work can't cut and paste.
and make it work LOL
 
Status
Not open for further replies.

Latest threads

Back
Top