Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Flexis — Parallax Forums

Need help with Flexis

HumanOzzHumanOzz Posts: 13
edited 2010-08-01 17:33 in Propeller 1
Hey guys,

I need some good suggestions on how to solve the things i'm doing in my project.
Well basically, i want to use more than 8 Flexi sensors in 1 propeller chip and the problems with this is.
Flexi sensors use RCTIME object right, and when used in the background mode, its making use of a new cog with it.
What i mean is, 1 flexi sensor uses 1 cog. So i'm wasting a cog.
But if we use the RCTIME in the forground mode, the main program waits for the change in the pin state because of the waitpeq command and from what i read, the propeller goes into a low-powered mode.
So, from what i understand, if the main program waits for the change in the state of this one pin, then it wont be able to detect any changes in the other pins that i have connected with flexi sensors right.

Is there some ways to do this?
I have thought of using more than 1 more propeller chips, where the other chip handles the flexi sensors in the background mode and send the data to the main chip. But then, its kind of a waste of chips right.
I need a good idea on how to efficiently use the flexi sensors without using more than 1 propeller chip.
Can you help guys?
Thanks

Comments

  • AribaAriba Posts: 2,690
    edited 2010-08-01 09:58
    You can measure all the Flex Sensors one after the other.
    If you don't want that the main cog needs to wait until all the sensors are measured then do this in a separate cog.
    The main cog can then read the values from the FlexValue array.

    You can spare a lot of components with the attached circuit.
    The code to measure all the sensors looks like that:
    CON
     MsrPin  = 0     'Pin settings
     Flex1   = 1
     Flex2   = 2
     ...
    VAR
     long FlexValue[noparse][[/noparse]8]
    OBJ
     rc : "rctime"
    
    PUB
     ...
     dira[noparse][[/noparse]Flex1] := 1
     rc.rctime(MsrPin,1,@FlexValue[noparse][[/noparse]0])
     dira[noparse][[/noparse]Flex1] := 0
     dira[noparse][[/noparse]Flex2] := 1
     rc.rctime(MsrPin,1,@FlexValue[noparse][[/noparse] 1])
     dira[noparse][[/noparse]Flex2] := 0
     dira[noparse][[/noparse]Flex3] := 1
     rc.rctime(MsrPin,1,@FlexValue[noparse][[/noparse] 2])
     dira[noparse][[/noparse]Flex3] := 0
     ...
    
    
    
    


    This writes the results in the FlexValue array.

    Andy

    Post Edited (Ariba) : 8/1/2010 11:43:52 AM GMT
    240 x 149 - 1K
  • HumanOzzHumanOzz Posts: 13
    edited 2010-08-01 10:24
    Thanks for reply ariba,
    hmm, this looks good, but dont you think the main program stops the assigned cog too fast for the readings to get to its real value?
    i mean, if you can see from the program,
    The gap between rctime.start and another rctime.start is kindof short.
  • AribaAriba Posts: 2,690
    edited 2010-08-01 12:03
    It may be you have seen my post to early, I have it edited after some minutes.
    If you use rctime in Foreground mode then it waits until one measurement is done.

    The voltage at the Capacitor looks like that:
    attachment.php?attachmentid=72103

    And here the variation to do all measuring in background with a second cog:
    CON
     MsrPin  = 0     'Pin settings
     Flex1   = 1
     Flex2   = 2
     ...
    VAR
     long FlexValue[noparse][[/noparse]8]
     long stack[noparse][[/noparse]20] 
    OBJ
     rc : "rctime"
    
    PUB main
     cognew(flexMsr,@stack)
     ...
     val = FlexValue[noparse][[/noparse] 1]   'Read a value
     ..
    
    PUB flexMsr
     repeat
       dira[noparse][[/noparse]Flex1] := 1
       rc.rctime(MsrPin,1,@FlexValue[noparse][[/noparse]0])
       dira[noparse][[/noparse]Flex1] := 0
       dira[noparse][[/noparse]Flex2] := 1
       rc.rctime(MsrPin,1,@FlexValue[noparse][[/noparse] 1])
       dira[noparse][[/noparse]Flex2] := 0
       dira[noparse][[/noparse]Flex3] := 1
       rc.rctime(MsrPin,1,@FlexValue[noparse][[/noparse] 2])
       dira[noparse][[/noparse]Flex3] := 0
       ...
    
    



    Andy
    251 x 142 - 1K
  • HumanOzzHumanOzz Posts: 13
    edited 2010-08-01 12:32
    yeah, its true that if we use rc.rctime, we'll wait until the measurement is done.
    But then, if for example, we are at this point "rc.rctime(MsrPin,1,@FlexValue[noparse][[/noparse]0])",
    and lets say, that flexi sensor involved doesnt detect any changes, the program will wait at this point until theres a change in state right? (which happen if we place some pressure at that flexi sensor). Because of the waitpeq.
    What i mean is, if the program is at that point, waiting and waiting for the change of state, it wont be able to detect any changes that happens at the other flexis right?
    What do you think?
  • mparkmpark Posts: 1,305
    edited 2010-08-01 16:39
    The waitpeq just waits until the capacitor is discharged. It is not waiting on a change of state in the sensor. Perhaps you are confused by the comments about "state" in rctime.spin. Those refer to the capacitor's state (i.e., charged or discharged).
  • AribaAriba Posts: 2,690
    edited 2010-08-01 17:27
    OK, I see your problem. The Flexi Sensor has ~5 MOhm when not pressed and ~20 kOhm when pressed.
    So you need a rctime with timeout to not slow it down to much.

    Here a possible code:
    CON
     MsrPin  = 0     'Pin settings
     Flex1   = 1
     Flex2   = 2
     ...
     TMOUT   = ?     '~10us resolution
    VAR
     long FlexValue[noparse][[/noparse]8]
     long stack[noparse][[/noparse]20] 
    
    PUB main
     cognew(flexMsr,@stack)
     ...
     val = FlexValue[noparse][[/noparse] 1]   'Read a value
     ..
    
    PUB flexMsr
     repeat
       dira[noparse][[/noparse]Flex1] := 1
       FlexValue[noparse][[/noparse]0] := rctime(MsrPin,1,TMOUT)
       dira[noparse][[/noparse]Flex1] := 0
       dira[noparse][[/noparse]Flex2] := 1
       FlexValue[noparse][[/noparse] 1] := rctime(MsrPin,1,TMOUT)
       dira[noparse][[/noparse]Flex2] := 0
       dira[noparse][[/noparse]Flex3] := 1
       FlexValue[noparse][[/noparse] 2] := rctime(MsrPin,1,TMOUT)
       dira[noparse][[/noparse]Flex3] := 0
       ...
    
    PUB rctime(pin,state,timeout) : time
      outa[noparse][[/noparse]pin] := state                   'make I/O an output in the state
      dira[noparse][[/noparse]pin] := 1                               
      waitcnt(clkfreq/1000 + cnt)          'pause for 1mS to charge cap
      dira[noparse][[/noparse]pin] := 0                       'make I/O an input
      time := cnt                          'grab clock tick counter value
      repeat until ina[noparse][[/noparse]pin]<>state or timeout==0   'wait until pin goes into opposite state
        timout--                           ' or timout
      if timeout==0
        return -1                          '
      time := cnt - time                   'clock cycles passed state changed
      time := (time-1600) >> 4             'offset adjustment and scale
    
    


    This is not tested! It's a bit dangerous to post such a code without testing, but I have not the time now.
    Perhaps you need to adjust the offset adjustment. The timout is in ~10 microseconds steps (the repeat loop time).

    BTW: I think there is a bug in the original rctime object at the watpeq. With state = 0 and Pin > 0 it will not work.
    WAITPEQ((1-State)<<Pin, |<Pin, 0) would be better.

    Andy
  • HumanOzzHumanOzz Posts: 13
    edited 2010-08-01 17:28
    Yeah thats right, but for this case, dont you think that the capacitor wont be discharged if the flexi doesnt detect anything at all. So its like, its waiting for some pressure to be applied then it will proceed to the next flexi sensor.
  • HumanOzzHumanOzz Posts: 13
    edited 2010-08-01 17:33
    Thanks ariba, i think thats the thing i'm looking for. [noparse]:)[/noparse]
Sign In or Register to comment.