Shop OBEX P1 Docs P2 Docs Learn Events
A/D W/O External Circuitry? — Parallax Forums

A/D W/O External Circuitry?

SRLMSRLM Posts: 5,045
edited 2008-12-16 08:08 in Propeller 1
Is it possible to use the Propeller to measure an analog signal (voltage) without using an external chip? I'm using this sensor to measure some distances, and it outputs between 0 and 5 volts, with 2.5 volts the effective minimum. I'm guessing that I can use a resistor (4.7 kOhm?) just like any other five volt device, but what about getting useful distance information from it?

Comments

  • kwinnkwinn Posts: 8,697
    edited 2008-12-16 04:31
    See the info on using 2 pins as a sigma/delta adc.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-16 04:59
    The best source of info is the application note on the cog counters (AN001) downloadable from the Propeller Downloads webpage. It includes sample code.
  • SRLMSRLM Posts: 5,045
    edited 2008-12-16 05:55
    Wow. A whole object titled ADC: just what I'm looking for! However, I do have a question: I don't want to dedicate a whole cog just to the measurement, so if I can I would like to integrate it into my existing spin application. My guess is that I could simply modify the command
    jmp       #:loop                          'wait for next sample period
    

    to jump to a spin method, but then I get confused about spin living in the hub, and assembly in the cog. Is it a viable modification to do this?

    What appears to my non-assembly programmer eye to be the main loop:
    :loop         waitcnt   asm_cnt,asm_cycles              'wait for next CNT value (timing is determinant after WAITCNT)
    
                  mov       asm_sample,phsa                 'capture PHSA and get difference
                  sub       asm_sample,asm_old
                  add       asm_old,asm_sample
                                                             
                  wrlong    asm_sample, par
        
                  jmp       #:loop                          'wait for next sample period
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-16 06:13
    You can't mix Spin and assembly in the same cog. There's a Spin interpreter that's a large assembly program that fills the cog when you're running Spin. Unless you absolutely have to reuse the cog that's used for doing the ADC, you should dedicate a cog to the function and leave it that way. It takes about 100us to start up a cog so you could make a few measurements, then load some other program into the cog, then reload the ADC program as long as you're not in a hurry.
  • TubularTubular Posts: 4,656
    edited 2008-12-16 08:08
    hi Srlm,

    I'm looking to use the same sensor as a backup to a maxbotix ultrasonic ranger. The curve for that sharp sensor is very flat as the distance ranges out beyond 3 metres. (perhaps 50 mv per meter) So i'll be interested to hear how the sigma delta goes. For my application I'm going straight to an external adc.

    tubular
Sign In or Register to comment.