input and save input

Status
Not open for further replies.
Calm down Jon....It really isn't worth dying over!!! ( I think secretly you love it all!!!)

Burt!! If that is you in your avatar, at least you can't pull your hair out!!

MrDeb!! Wasn't this for Christmas?? Do yourself a favour.. Re-read all the posts... All your answers have already been given, time and time again..

All... Go easy... This is a hobby to MrDeb... You know!! Fun...
 
ADC read 80*500/1024= 39 why
he is doing that is beyond me 500/1024 = .488 you are cutting the adc readings in about haft
when you could of just used the adc reading you get with adc.read()
None of the 500/1024 is needed
 
I don't know why it works with or without?
I have 10 leds which indicate which section of the ladder is connected to the ADC input port.
Later today going to investigate further what is going on and hopefully why.
The code I posted in #209 works as well but not entirely, it skips one "switch" so adding the TRISA and the ADCON statements ddidn't seem to make much difference.
The reason I am using the 500/1023 is the fact most if not all the ADC examples use this.
 
Ian, I really don't explain things for MrDEB's behalf. I explain them for anyone else who may foolishly try to follow what he's doing.

Regarding MrDEB's post above, there are so many things wrong with that... I'll just give the coding project to the team of monkeys in the typing pool. I think they could have finished by now.

Regarding JimB's comment in post #214 about connecting an LCD to see what values the ADC is returning - that's a logical idea that most people would follow. It might explain the mystery of "Dividing by 2 or not doesn't seem to make any difference" and "Enabling the ADC or not doesn't seem to matter". But MrDEB's success with connecting an LCD parallels his success here......

But there is an easy way to monitor program output if you use a PICkit2. The PICkit 2 GUI has a terminal emulator built in. If your software supports a soft UART, you can set it up to squirt serial data out PortB.7. which the pin the PICkit 2 uses for terminal input, and is where the PICkit 2 is connected for ICSP programming. Program your board, then click to the terminal emulator to see results.

This procedure is more fully described here: Not Quite Trivial - A Tip For Using The Software UART With The PICkit 2
 
Did you read the fact
The reason I am using the 500/1023 is the fact most if not all the ADC examples use this.
If you look you'll see it tell's you that you scale the reading to get voltage.
They scaled to give a voltage that you display

You don't need to scale.
You don't need voltage you need 0 to 1023 that's it.
You would end up with 102 204 306 409 511 613 716 818 920 1023
And test 100 200 300 400 500 600 700 800 900 1000
Or do it the smart way print each switch out nock 10 off and test that.
 
Last edited:
If you add 51 and divide by 102 you get the switch number. I can here an echo in here.

Mike.
 
Burt!! Don't get hung up on the ADC output scaling... His variable "position" doesn't have scaling.. The 5v conversion isn't being used..
 
I'm not hung up

He's using this
Code:
position = Get_ADC_Sample
Thats pulled from this
Code:
FUNCTION Get_ADC_Sample() AS WORD // Function to grab the ADC sample for player position
result = ADC.Read(0)*500/1024 // Grab an ADC sample from channel 0
END FUNCTION
That gives him 49 for player 10 99 for player 11
And I'm going to skip the rest to player 9 which is 500
This is why he thinks he needs to.
Mrdeb's words
The reason I am using the 500/1023 is the fact most if not all the ADC examples use this.
Code:
// read the AD port and scale for 0 - 5 volts...
function ADInAsVolt() as word
   result = (ADC.Read(0) + 1) * 500 / 1024
end function

Right out of swordfish
Don't need to scale the adc.read()
 
Last edited:
I'm not hung up

He's using this
OIC.... Sorry Burt... The scaling is being used...

MrDeb!! You are correct.... The equation is used everywhere, but only if you want the ADC to represent 0 ~ 5volts..

However!! On this occasion it isn't needed... you are looking for a value of 0 ~ 1024... Using the equation you only have 0~499. The more resolution you have gives a better distinction between values..
 
If we look at MrDEB's remarks, i.e., it doesn't matter if he multiplies by 500/1024 or not and it doesn't matter if the ADC is enabled or not, it's pretty clear that MrDEB doesn't have a clue what value is being read from the ADC.

JimB suggested adding an LCD so he could see what value is being read....but in the past that hasn't worked so well.

I suggested an easy way of using the PICkit 2 GUI's terminal emulator so he could see the value. This is pretty simple to do if you follow the directions and copy&paste a few lines of code.

Easier still, MrDEB could read the ADC and use a for/next loop to toggle an LED the number of times equal to the value read

Some how, MrDEB needs to be able to see the result of the ADC read command. The rest of his code and his deductive reasoning skills aren't up to the task of figuring out what's going on without know what numbers arw being read.
 
I contemplated using the usart but not real comfortable. I did connect an LCD but it only output voltage. I am curious if one could output RESULT.
Curious about the scaling (post #229 ). Also wondering if the SETALLDIGITAL is affecting the ADC reading.
Planing on experimenting with this as well as using an example I found where 5000/1024 was used. SETALLDIGITAL was not used.
The only reason I want to see the ADC read is to determine if I have the correct CASE SELECT figures.
Mikes idea of in post #226. Have tried this and it gets some progress.
 
I did connect an LCD but it only output voltage. I am curious if one could output RESULT.
This is because you are using the "adc *500/1024"

Replace this
FUNCTION Get_ADC_Sample() AS WORD // Function to grab the ADC sample for player position
result = ADC.Read(0)*500/1024 // Grab an ADC sample from channel 0
END FUNCTION.

with this..
FUNCTION Get_ADC_Sample() AS WORD // Function to grab the ADC sample for player position
result = ADC.Read(0) // Grab an ADC sample from channel 0
END FUNCTION
 
Lets assume for a moment that many people here understand how the ADC works, and know that the 10 bit ADC of the PIC will return a value from 0 to 1023 inclusive.

Lets further assume that the several people who have said the results for the button presses will range from about 35 counts to 900- some counts.

What happens when you multiply the ADC result by 500/1024? You cut the result just about in half. So instead of a range of 0 - 1023, now you have a range of 0 - 500. You are expecting results of up to 900-something, but now you get a maximum value of only 500. Half your switches can't possibly work with the values people have calculated and tested to be true.

So how about multiplying by 5000/1024? Now the values are 5 times too big.

Stop and think. People HERE have calculated and tested values for EXACTLY what you are doing. Calculated and PROVEN the values are correct. Do you think people here who KNOW WHAT YOU ARE DOING may understand more than example code completely unrelated to what you are doing?

If you have displayed voltages on the LDC, why can you not show RESULTS? YOU are the one typing what to display!
 
I posted that days ago LOL
Mikes post is dead simple it would give a players number 1 to 10 based on the raw adc reading.
 
using same circuit as post#236 but with 5v my readings are not linear as should be but will live with it. Using the function with just the ADC(0) only the "switch" termination reading tend to be way off. Am reading what the port input is then using 1024/5*voltage reading should be what is used in the CASE SELECT.
4.45 =911
3.97= 813
3.04=622
2.57=526
2.10=430
1.64=335
1.17=239
.708=144
.242=49
.224=45
Am I missing something?for not being linear.
As for the 5000/1024, yes there is an example that uses this to read 10 switches. DDIYwebsite, search "keypad test"
 
Yes MrDeB Jon was displaying voltage your playing a game and Jon new what he was doing You want 10 players he wanted something else.

And seeing no one read's all this stuff we keep going on I done told you what you'd end up with all but the 43 you should not have 43 first reading should be 49 last should be closer to 1000 but why Your not guess you mixed some 20% resistors

I hand picked 10 they all read the same.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…