Shop OBEX P1 Docs P2 Docs Learn Events
Coming from SX to Prop need some advice. — Parallax Forums

Coming from SX to Prop need some advice.

turboturbo Posts: 24
edited 2011-01-25 22:05 in Propeller 1
I have been using the SX for a few years now and i have a few commercial products using them right now, my supply is getting low on the SX's and i have already started to port my code from the SX over to the Prop .

My device talks to a automotive dash through serial and that part works fine on the prop now i need it to read 2 analog signals 0-5v range , on the SX i use Analogin but i havent found a similar example on the prop , my analog signals have pullups on there lines and as they move through there range the get closer to ground.

I seen RCtime in the examples but i dont think that will work ( or will it) ?

Does PropBasic have a equivalent to ANALOGIN ?

Comments

  • HShankoHShanko Posts: 402
    edited 2011-01-25 19:48
    Look at AN001, at the sigma-delta A/D scheme. Uses two R and two C for basic design. Works for many applications.
  • TtailspinTtailspin Posts: 1,326
    edited 2011-01-25 19:58
    That is exactly what RC time is for, so it should work for many Analog to Digital conversions..

    Have You considered the "MCP3202".? It may be something You could use.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-25 20:02
    Here's a simple bit of code that let's you read an RC circuit; I use it in the EFX-TEK AP-16+
    pub readpot(p)
    
    '' Reads RC circuit on pin p
    '' -- takes about 2ms
    '' -- assumes 10K + 0.01uF
    
      ctra := (%01000 << 26) | p                                    ' ctra in pos detect mode 
      frqa := 1
    
      outa[p] := 1                                                  ' charge cap
      dira[p] := 1
      waitcnt((clkfreq >> 10) + cnt)                                ' ~1ms @100MHz
    
      phsa := 0                                                     ' clear counter
      dira[p] := 0                                                  ' allow discharge
      waitcnt((clkfreq >> 10) + cnt)
      ctra := 0                                                     ' disable ctra
      
      return (phsa >> 4) <# 500                                     ' return discharge time
    

    Note that the last line divides the result down and limits it to 500 -- this worked for my program.

    I, too, am a fan of the MCP320x family and have used it in several projects.
  • turboturbo Posts: 24
    edited 2011-01-25 21:16
    Thanks guys for the point in the right direction .

    One last question before i dive in , will the 220ohm series resistor in the RCtime circuit be sufficient to protect the input pin from my 0-5v analog sensor since the prop is a 3.3v chip?
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-25 22:05
    I wouldn't use an RC circuit to measure a 5v input -- best to swtich to an ADC like the ADC0832 or MCP3202. Its okay to connect them to 5v, just put a 2.2K resistor into the DIO line. This article will help:

    -- http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp8.pdf
Sign In or Register to comment.