Shop OBEX P1 Docs P2 Docs Learn Events
Trouble with ADC0831 and ASCII — Parallax Forums

Trouble with ADC0831 and ASCII

Paul ThompsonPaul Thompson Posts: 5
edited 2006-10-07 00:42 in BASIC Stamp
I am experimenting with a pot and a ADC0831 chip in order to read voltage and convert the analog to digital and display in on screen using the DEBUG commands. This works fine, but I now want to go a step further and compare the output of the ADC (ASCII) with a number (integer). I want to use different reading from the pot in order to control the speeds of a motor using PWM. I have the set-up, but I cannot seem to compare numbers (ASCII given by the ADC and integers) in order to do this. What can I do?

Comments

  • Sutton MurraySutton Murray Posts: 88
    edited 2006-10-06 20:07
    I am not to sure what you mean, but if i understand you right you are receiving a binary format values (0 and 1). If so you need to look at the DEC command. DEC Will transform to decimal, HEX to Hexdecimal. Value will then be from 0 to 256 as you turn the pot. Only 256 as the 0831 is a 8 bit Chip with only 256 steps possibilities from the pot.
  • Paul ThompsonPaul Thompson Posts: 5
    edited 2006-10-06 22:18
    Yes, I understand that DEC and HEX will change it using the DEBUG command, but what I want to do is take the output from the ADC chip and compare it to actual numbers that I established in the program, i.e. the sub routine:
    Run_Motor:
    result = adcBits
    FOR result = 1 TO 25
    speed = 750
    NEXT
    FOR result = 26 TO 50
    speed = 820
    NEXT
    FOR result = 51 TO 75
    speed = 835
    NEXT
    FOR result = 76 TO 100
    speed = 850
    NEXT
    FOR result = 101 TO 125
    speed = 875
    NEXT
    FOR result = 126 TO 150
    speed = 900
    NEXT
    FOR result = 151 TO 175
    speed = 925
    NEXT
    FOR result = 176 TO 200
    speed = 950
    NEXT
    FOR result = 201 TO 225
    speed = 975
    NEXT
    FOR result = 226 TO 255
    speed = 1000
    NEXT
    PAUSE 20
    PULSOUT HB25, speed '750=stop, 1100 full fwd, 400 full reverse
    PAUSE 7
    RETURN

    where 'adcBits' is the raw results of the ADC chip and 'result' is the variable that I want to compare the numbers to. When I throw in DEC in front of 'adcBits' the compiler throws an error. Don't know what the deal is... hope that clarifies my question.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-06 22:46
    First you have to fix the program. The "FOR" statement is not what you want to use. It looks like you've divided the ADC range into blocks of 25 values (roughly) and want a particular servo speed that corresponds to the block of ADC values. First, you can reduce the ADC range to an index as follows (this assumes that zero is not a valid value), then convert to a speed value:
    result = (adcBits - 1) / 25
    LOOKUP result, [noparse][[/noparse]750, 820, 835, 850, 875, 900, 925, 950, 975, 1000, 1000], speed
    
    


    You can always add a specific check for zero and the 1000 is duplicated for the values from 251-255.
  • Paul ThompsonPaul Thompson Posts: 5
    edited 2006-10-07 00:42
    Mike, thank you for the code... works perfect and looks a whole lot neater... I am new to this stuff and I am grateful to have a tool like this forum to learn and ask questions. Thanks again, Mike.
    -Paul
Sign In or Register to comment.