Strange Quirk with DAC

Bayside888

Active member
This is a snippet of a program on the 28X2:
The Code below does NOT work -- the output on pin A.2 stays constant. However, if I comment out the line starting with "if junk>50..." then the code works fine to output an increasing voltage on A.2. I tried different things, including a "DirsA" statement, etc., and finally found the problem by pure chance (and about 2 hours). Any ideas?? Thanks

Code:
symbol DAC_pin=W2
symbol counter = W4
symbol junk=W10

start:
    Wait_loop:
        for counter = 0 to 5
            pause 1000            ;wait for keypress
            readadc10 A.1,junk        ;test for keypress
            if junk>50 then display        ;jump if key pressed, about zero then loop
        next   

low a.2
dacsetup %10100000        ;set for A.2, supply volt max, gnd min

for counter = 0 to 31
    daclevel Counter
    pause 1500
next counter

goto start
    
display:
 
A READADC10 result >50 means that your code will jump to the label display: whenever the voltage on pin A.1 is greater than 0.244 volts, which seems quite low.
Is this what you intend?
If you have a switch connected to pin A.1 that connects the pin to 5V when the switch is pressed then try using a higher setting for your test. e.g. > 511 to test for a voltage greater than about 2.5v when the switch is pressed.
 
Back
Top