Shop OBEX P1 Docs P2 Docs Learn Events
When I run my code, should it work? — Parallax Forums

When I run my code, should it work?

turbosupraturbosupra Posts: 1,088
edited 2009-10-31 15:01 in Propeller 1
I'm not sure when I'll have time at home to sit down and test this and build the resistor ladder, but can anyone see any problems (there has to be some, I'm new [noparse]:)[/noparse] ) with this code?


' Test circuit for voltage values


[b]pub[/b] Pumptest

  [b]repeat[/b]                                                                        
    [b]dira[/b][noparse][[/noparse]*1..7] := %0000000                                                      ' sets pins 1 through 7 to inputs
    [b]ina[/b][noparse][[/noparse]* 1]  := 0                                                               ' sets pin 1 to be an input for an rpm value
    [b]ina[/b][noparse][[/noparse]* 2]  := 0                                                               ' sets pin 2 to look for a ground signal input
    [b]ina[/b][noparse][[/noparse]* 3]  := 1                                                               ' sets pin 3 to a positive voltage input (1.65v)
    [b]ina[/b][noparse][[/noparse]* 4]  := 1                                                               ' sets pin 4 to a positive voltage input (1.85v)
    [b]ina[/b][noparse][[/noparse]* 5]  := 1                                                               ' sets pin 5 to a positive voltage input (2.05v)
    [b]ina[/b][noparse][[/noparse]* 6]  := 1                                                               ' sets pin 6 to a positive voltage input (1.40v)
    [b]ina[/b][noparse][[/noparse]* 7]  := 1                                                               ' sets pin 7 to a positive voltage input (1.59v)
    [b]dira[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 to an output
    [b]outa[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 as an output type of positive voltage



  [b]repeat[/b]
    [b]while[/b] ([b]ina[/b][noparse][[/noparse]* 1] := 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] <> 0)                                    ' while pin 1 is not receiving a pulsing ground signal and pin 2 does not receive a ground signal
           [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 3] [b]until[/b] [b]ina[/b][noparse][[/noparse]* 1] > 0                               ' connect input pin 3 to output pin 8 and repeat until it receives a signal on pin 1                                                                    

    [b]while[/b] ([b]ina[/b][noparse][[/noparse]* 1] > 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] := 0)                                     ' while input pin 1 has a pulsing ground signal and  pin 2 has a ground signal
           [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 4]                                                  ' repeat until this input is greater than 0 and is receiving a ground

    [b]if[/b]  [b]ina[/b][noparse][[/noparse]* 1] > 0 [b]AND[/b] [b]ina[/b][noparse][[/noparse]* 2] <> 0                                           ' if pin 1 receives a pulsing ground signal, but pin 2 does not receive a ground signal
        [b]repeat[/b]
           [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 7]                                                  ' connect output pin 8 to input pin 7 and pass the voltage value
           [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' sets output pin 8 to input pin 7 value for 500 milli seconds
           [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 6]                                                  ' connect output pin 8 to input pin 6 and pass the voltage value 
           [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' keeps outa[noparse][[/noparse]*8] at ina[noparse][[/noparse]*6]'s value for 500 milli seconds, then repeats endlessly until ina[noparse][[/noparse]* 1] = 0
           



Post Edited (turbosupra) : 10/9/2009 12:41:09 AM GMT
«13

Comments

  • mparkmpark Posts: 1,305
    edited 2009-10-08 21:43
    The forum software swallows some bracketed text, such as "[noparse][[/noparse]" followed by "1" followed by "]", so the code you posted is a little messed up. When posting code, please insert a space ("[noparse][[/noparse] 1]") or use the formatter in PhiPi's toolbar: http://phipi.com/forum/.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-10-08 22:03
    When you are editing code using your Propeller Tool, you can hit your F8 key and get some preliminary feedback that checks for bad expression terms, missing called objects, etc.
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 00:39
    Ok, I changed the formatting, hopefully it's readable [noparse]:)[/noparse]

    roll.gif
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 02:48
    Here is what seemed not to error out in the spin code

    It appears as if the way this code is written for repeat would be repeat -> while -> variable equals these conditions, then if it does not, it moves to the next line of code or in this case, the next repeat statement?

    Is it correct to write in the first repeat statement, that if ina2 does not equal 0 to represent that input pin 2 is NOT receiving a ground signal? Since I've defined it as a low side input up top?



    ' Test circuit for voltage values
    
    
    [b]var[/b]
      [b]long[/b] x
           
    
    [b]pub[/b] Pumptest
    
      [b]repeat[/b]                                                                        
        [b]dira[/b][noparse][[/noparse]*1..7] := %0000000                                                      ' sets pins 1 through 7 to inputs
        [b]ina[/b][noparse][[/noparse]* 1]  := 0                                                               ' sets pin 1 to be an input for an rpm value
        [b]ina[/b][noparse][[/noparse]* 2]  := 0                                                               ' sets pin 2 to look for a ground signal input
        [b]ina[/b][noparse][[/noparse]* 3]  := 1                                                               ' sets pin 3 to a positive voltage input (1.65v)
        [b]ina[/b][noparse][[/noparse]* 4]  := 1                                                               ' sets pin 4 to a positive voltage input (1.85v)
        [b]ina[/b][noparse][[/noparse]* 5]  := 1                                                               ' sets pin 5 to a positive voltage input (2.05v)
        [b]ina[/b][noparse][[/noparse]* 6]  := 1                                                               ' sets pin 6 to a positive voltage input (1.40v)
        [b]ina[/b][noparse][[/noparse]* 7]  := 1                                                               ' sets pin 7 to a positive voltage input (1.59v)
        [b]dira[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 to an output
        [b]outa[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 as an output of positive voltage
    
      x := 0
    
      [b]repeat[/b]
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] := 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] <> 0)                         ' while pin 1 is not receiving a pulsing ground signal and pin 2 does not receive a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 3]                                                  ' connect input pin 3 to output pin 8 and repeat until it receives a signal on pin 1                                                                    
    
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] > 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] := 0)                          ' while input pin 1 has a pulsing ground signal and  pin 2 has a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 4]                                                  ' repeat until this input is greater than 0 and is receiving a ground
    
        [b]repeat[/b] [b]while[/b] x := [b]ina[/b][noparse][[/noparse]* 1] > 0 [b]AND[/b] [b]ina[/b][noparse][[/noparse]* 2] <> 0                              ' while pin 1 receives a pulsing ground signal, but pin 2 does not receive a ground signal
          [b]repeat[/b]
               [b]outa[/b][noparse][[/noparse] *8] := [b]ina[/b][noparse][[/noparse]* 7]                                                    ' connect output pin 8 to input pin 7 and pass the voltage value
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' sets output pin 8 to input pin 7 value for 500 milli seconds
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 6]                                                    ' connect output pin 8 to input pin 6 and pass the voltage value 
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' keeps outa[noparse][[/noparse]*8] at ina[noparse][[/noparse]*6]'s value for 500 milli seconds, then repeats endlessly until ina[noparse][[/noparse]* 1] = 0
               
    
    
    

    Post Edited (turbosupra) : 10/9/2009 3:17:37 AM GMT
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 03:17
    Or should it look like this? (changes were made in the last repeat section)





    ' Test circuit for voltage values
    
    
    [b]var[/b]
      [b]long[/b] x
           
    
    [b]pub[/b] Pumptest
    
      [b]repeat[/b]                                                                        
        [b]dira[/b][noparse][[/noparse]*1..7] := %0000000                                                      ' sets pins 1 through 7 to inputs
        [b]ina[/b][noparse][[/noparse]* 1]  := 0                                                               ' sets pin 1 to be an input for an rpm value
        [b]ina[/b][noparse][[/noparse]* 2]  := 0                                                               ' sets pin 2 to look for a ground signal input
        [b]ina[/b][noparse][[/noparse]* 3]  := 1                                                               ' sets pin 3 to a positive voltage input (1.65v)
        [b]ina[/b][noparse][[/noparse]* 4]  := 1                                                               ' sets pin 4 to a positive voltage input (1.85v)
        [b]ina[/b][noparse][[/noparse]* 5]  := 1                                                               ' sets pin 5 to a positive voltage input (2.05v)
        [b]ina[/b][noparse][[/noparse]* 6]  := 1                                                               ' sets pin 6 to a positive voltage input (1.40v)
        [b]ina[/b][noparse][[/noparse]* 7]  := 1                                                               ' sets pin 7 to a positive voltage input (1.59v)
        [b]dira[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 to an output
        [b]outa[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 as an output of positive voltage
    
      x := 0
    
      [b]repeat[/b]
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] := 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] <> 0)                         ' while pin 1 is not receiving a pulsing ground signal and pin 2 does not receive a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 3]                                                  ' connect input pin 3 to output pin 8 and repeat until it receives a signal on pin 1                                                                    
    
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] > 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] := 0)                          ' while input pin 1 has a pulsing ground signal and  pin 2 has a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 4]                                                  ' repeat until this input is greater than 0 and is receiving a ground
    
        [b]repeat[/b] [b]while[/b] x := [b]ina[/b][noparse][[/noparse]* 1] > 0 [b]AND[/b] [b]ina[/b][noparse][[/noparse]* 2] <> 0                              ' while pin 1 receives a pulsing ground signal, but pin 2 does not receive a ground signal
          
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 7]                                                    ' connect output pin 8 to input pin 7 and pass the voltage value
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' sets output pin 8 to input pin 7 value for 500 milli seconds
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 6]                                                    ' connect output pin 8 to input pin 6 and pass the voltage value 
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' keeps outa[noparse][[/noparse]*8] at ina[noparse][[/noparse]*6]'s value for 500 milli seconds, then repeats endlessly until ina[noparse][[/noparse]* 1] = 0
                  
    
    
    
  • mparkmpark Posts: 1,305
    edited 2009-10-09 03:29
    INA is read-only. Assigning to it doesn't do anything useful.

    Also, in this line
    repeat while x := (ina[noparse][[/noparse] 1] := 0) AND (ina[noparse][[/noparse] 2] <> 0)
    I'm not sure if you want ":=" (assignment) or "==" (test for equality).

    Post Edited (mpark) : 10/9/2009 3:34:14 AM GMT
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 03:33
    I can't pass a voltage value read by an ina, to an outa?

    I want is equal to, so I guess I want == ?

    mpark said...
    INA is read-only. Assigning to it doesn't do anything useful.

    Also, in this line
    repeat while x := (ina[noparse][[/noparse] 1] := 0) AND (ina[noparse][[/noparse] 2] <> 0)
    I'm not sure if you want ":=" (assignment) or "==" (test for equality).
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-10-09 03:36
    Everything looks totally wrong, you are trying to assign values to inputs and somehow magically to become a specified voltage etc.
    Take those statements that say " assign pin x to a positive voltage", what do you mean to do there because it just doesn't make sense.

    Better to post a diagram of your circuit and description of what you want to do I think.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 03:51
    ' Test circuit for voltage values
    
    
    [b]var[/b]
      [b]long[/b] x
           
    
    [b]pub[/b] Pumptest
    
                                                                             
        [b]dira[/b][noparse][[/noparse]*1..7] := %0000000                                                      ' sets pins 1 through 7 to inputs
        [b]ina[/b][noparse][[/noparse]* 1]  := 0                                                               ' sets pin 1 to be an input for an rpm value
        [b]ina[/b][noparse][[/noparse]* 2]  := 0                                                               ' sets pin 2 to look for a ground signal input
        [b]ina[/b][noparse][[/noparse]* 3]  := 1                                                               ' sets pin 3 to a positive voltage input (1.65v)
        [b]ina[/b][noparse][[/noparse]* 4]  := 1                                                               ' sets pin 4 to a positive voltage input (1.85v)
        [b]ina[/b][noparse][[/noparse]* 5]  := 1                                                               ' sets pin 5 to a positive voltage input (2.05v)
        [b]ina[/b][noparse][[/noparse]* 6]  := 1                                                               ' sets pin 6 to a positive voltage input (1.40v)
        [b]ina[/b][noparse][[/noparse]* 7]  := 1                                                               ' sets pin 7 to a positive voltage input (1.59v)
        [b]dira[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 to an output
        [b]outa[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 as an output of positive voltage
    
      x := 0
    
      [b]repeat[/b]
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] := 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] <> 0)                         ' while pin 1 is not receiving a pulsing ground signal and pin 2 does not receive a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 3]                                                  ' connect input pin 3 to output pin 8 and repeat until it receives a signal on pin 1                                                                    
    
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] > 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] := 0)                          ' while input pin 1 has a pulsing ground signal and  pin 2 has a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 4]                                                  ' repeat until this input is greater than 0 and is receiving a ground
    
        [b]repeat[/b] [b]while[/b] x := [b]ina[/b][noparse][[/noparse]* 1] > 0 [b]AND[/b] [b]ina[/b][noparse][[/noparse]* 2] <> 0                              ' while pin 1 receives a pulsing ground signal, but pin 2 does not receive a ground signal
          
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 7]                                                  ' connect output pin 8 to input pin 7 and pass the voltage value
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' sets output pin 8 to input pin 7 value for 500 milli seconds
               [b]outa[/b][noparse][[/noparse]* 8] := [b]ina[/b][noparse][[/noparse]* 6]                                                  ' connect output pin 8 to input pin 6 and pass the voltage value 
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' keeps outa[noparse][[/noparse]*8] at ina[noparse][[/noparse]*6]'s value for 500 milli seconds, then repeats endlessly until ina[noparse][[/noparse]* 1] = 0
                  
    
    
    

    Post Edited (turbosupra) : 10/9/2009 4:16:53 AM GMT
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 03:53
    I don't know if you saw in the first post, but I'll have a resistor ladder controlling the voltages coming into the different pins.

    At this point I just want to have different voltage values coming into different pins via resistors, and then use the chip to output one of those based on other conditions


    Peter Jakacki said...
    Everything looks totally wrong, you are trying to assign values to inputs and somehow magically to become a specified voltage etc.
    Take those statements that say " assign pin x to a positive voltage", what do you mean to do there because it just doesn't make sense.

    Better to post a diagram of your circuit and description of what you want to do I think.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-10-09 04:01
    Yes I saw you mentioned a resistor ladder but a resistor ladder is normally used to generate an analog voltage from outputs, so how have you connected it? Rather than trying to guess or to continue asking many many questions it is far better that you post the diagram and then we help you.

    The Prop's pins do not read analog values so you can't have different voltages coming into the pins unless you are trying to rely upon switching thresholds, but there are better ways.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • SamMishalSamMishal Posts: 468
    edited 2009-10-09 04:06
    Hi Turbo

    The rest of your program will not run after the first repeat block.
      [b]repeat[/b]                                                                        
        [b]dira[/b][noparse][[/noparse]&shy;1..7] := %0000000                                                      ' sets pins 1 through 7 to inputs
        [b]ina[/b][noparse][[/noparse]&shy; 1]  := 0                                                               ' sets pin 1 to be an input for an rpm value
        [b]ina[/b][noparse][[/noparse]&shy; 2]  := 0                                                               ' sets pin 2 to look for a ground signal input
        [b]ina[/b][noparse][[/noparse]&shy; 3]  := 1                                                               ' sets pin 3 to a positive voltage input (1.65v)
        [b]ina[/b][noparse][[/noparse]&shy; 4]  := 1                                                               ' sets pin 4 to a positive voltage input (1.85v)
        [b]ina[/b][noparse][[/noparse]&shy; 5]  := 1                                                               ' sets pin 5 to a positive voltage input (2.05v)
        [b]ina[/b][noparse][[/noparse]&shy; 6]  := 1                                                               ' sets pin 6 to a positive voltage input (1.40v)
        [b]ina[/b][noparse][[/noparse]&shy; 7]  := 1                                                               ' sets pin 7 to a positive voltage input (1.59v)
        [b]dira[/b][noparse][[/noparse]&shy; 8] := 1                                                               ' sets pin 8 to an output
        [b]outa[/b][noparse][[/noparse]&shy; 8] := 1                                                               ' sets pin 8 as an output of positive voltage
    
    

    The program flow will stay for ever inside this loop and the rest of the program will never be executed.

    SPIN is indentation specific....I think you may need to indent the rest of your code to be on the same level
    as the ina[noparse]/noparse etc.

    You right now have the other code on the same level as the Repeat which means it is not going to execute ever.

    What will happen is that the dira[noparse]/noparse.....outa[noparse]/noparse· code will be repeated for ever since it is inside the BLOCK of the repeat.

    The other code is not indented so it will never be executed.



    Samuel



    Post Edited (SamMishal) : 10/9/2009 4:13:04 AM GMT
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 04:13
    @sam - thanks, I don't think that repeat is even necessary, so I'm going to remove it


    @Peter

    I'd have to draw a diagram I guess (but it sounds like it would be wrong), right now I am using the breadboard that comes with the PELabsFunKit.

    I'm getting a little confused, as 1 person implied the resistor ladder would work, and another has said I'd need a ADC? Maybe you can tell me the best way to have voltage coming into a certain pin on the propeller and then I can try and draw a diagram with that starting information?


    Peter Jakacki said...
    Yes I saw you mentioned a resistor ladder but a resistor ladder is normally used to generate an analog voltage from outputs, so how have you connected it? Rather than trying to guess or to continue asking many many questions it is far better that you post the diagram and then we help you.

    The Prop's pins do not read analog values so you can't have different voltages coming into the pins unless you are trying to rely upon switching thresholds, but there are better ways.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-10-09 04:18
    Can you describe what you are trying to do at least. Do you want to measure a voltage? If you take time to reply then take a couple more minutes and put some DETAIL in and this will save the constant back and forth guessing.


    P.S. I've run out of time for now, maybe someone else can assist you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 04:36
    I am trying to feed different preselected voltage values into different pins on the propeller

    Then based on a few changing input conditions, have the propeller change the value it outputs on/to a single output pin, to one of those preselected voltage values

    There is a bit of a description in my code commentary, I'll cut and paste it below


    ' sets pin 1 to be an input for an rpm value
    ' sets pin 2 to look for a ground signal input
    ' sets pin 3 to a positive voltage input (1.65v)
    ' sets pin 4 to a positive voltage input (1.85v)
    ' sets pin 5 to a positive voltage input (2.05v)
    ' sets pin 6 to a positive voltage input (1.40v)
    ' sets pin 7 to a positive voltage input (1.59v)
    ' sets pin 8 to an output
    ' sets pin 8 as an output of positive voltage
  • SamMishalSamMishal Posts: 468
    edited 2009-10-09 04:45
    Turbo,
    A resistor ladder is a DAC not a ADC....i.e. you convert a Digital value to an analog voltage level.

    If you are trying to read an Analog voltage level then the resistor ladder WILL NOT work......

    If your voltage level is coming from a variable resistor then you can use an RC-Decay to measure the
    resistor and dispense with having to measure the voltage.

    Otherwise you WILL NEED and ADC.....the Sigma-Delta method is cheap but hard to get working well.

    The best way is to use an ADC chip. Parallax sells many different ones and the OBEX has drivers for them.

    By the way
     [b]repeat[/b]
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]&shy; 1] := 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]&shy; 2] <> 0)                         ' while pin 1 is not receiving a pulsing ground signal and pin 2 does not receive a ground signal
     
    

    this code is trying to assign a value 0 to an Input pin..... will not work....


    Regards

    Samuel
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-09 12:35
    Hello TurboSupra,

    all the IO-PINs of the propeller can do DIRECTLY are FOUR things:

    a) if configured as input by DIRA[noparse][[/noparse] IO-PinNumber] := 0

    1) READING in a "0"
    2) READING in "1"

    both by using the command INA[noparse][[/noparse] IO-PinNumber]

    b) if configured as output by DIRA[noparse][[/noparse] IO-PinNumber] := 1

    1) Set voltagelevel to 0.0V by using the command OUTA[noparse][[/noparse] IO-PinNumber] := 0
    2) Set voltagelevel to 3.3V by using the command OUTA[noparse][[/noparse] IO-PinNumber] := 1

    NOTHING else. They are DIGITAL ON or OFF nothing inbetween.

    If you want conversion from a digital value to analog voltages you need a resistorladder with MORE than one IO-Pin

    example
    two IO-Pins
    with two IO-pins you have four combinations
    00
    01
    10
    11

    with four combinations you can create the following analog voltages

    00: 0.0V
    01: 1.1V
    10: 2.2V
    11: 3.3V

    as the Propeller-chip is a 3.3V device which will deliver 3.3V as maximum

    What other poster meant by asking for details

    your voltages are not a self-purpose.
    I don't think you want to have a ridiculous present for your father
    a propellerboard creating a voltage of 1.40V and say to your father
    "look if you measure on THAT pin you get 1.40V on the Voltagemeter-display !!"

    You are doing something else much more senseful with this voltage 1.40V

    WHAT is it ???

    If you describe your WHOLE project you will get good advice and it will take only 3 or 4 postings until your thing is working
    If you go on in the same way as above it will take 30 or 40 postings until you got your thing working

    If your whole project is "I want to get familiar with the propeller and first I would like to create analog voltages "
    OF COURSE that's a project too !
    If you write something about your knowledge-level of electronics and programming you will get advice you can really use

    From what you have written so far I guess your knowledge-level about electronics and programming is rather low.
    that REALLY OK just clarifiy it.

    If you ask simple questions the "a-little-bit-advanced-newbies" here will be happy that they can answer on postings too
    So just ask

    best regards

    Stefan

    Post Edited (StefanL38) : 10/9/2009 3:47:22 PM GMT
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 13:28
    Prop Key

    P1 = pulsing ground input
    P2 = ground input (may or may not be "on")
    P3 = voltage input, preselected voltage value
    P4 = voltage output






    Do you mean this?



    adc1.jpg


    or this?


    dac1b.jpg





    SamMishal said...
    Turbo,
    A resistor ladder is a DAC not a ADC....i.e. you convert a Digital value to an analog voltage level.



    If you are trying to read an Analog voltage level then the resistor ladder WILL NOT work......



    If your voltage level is coming from a variable resistor then you can use an RC-Decay to measure the
    resistor and dispense with having to measure the voltage.



    Otherwise you WILL NEED and ADC.....the Sigma-Delta method is cheap but hard to get working well.



    The best way is to use an ADC chip. Parallax sells many different ones and the OBEX has drivers for them.



    By the way


     [b]repeat[/b]
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] := 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] <> 0)                         ' while pin 1 is not receiving a pulsing ground signal and pin 2 does not receive a ground signal
      
    
    


    this code is trying to assign a value 0 to an Input pin..... will not work....





    Regards



    Samuel
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-10-09 13:32
    turbo, communication is maybe not one of your better skills, perhaps you are good at other things, maybe you are a good musician. You keep trying to tell us HOW you are doing it but we want you to tell us WHAT you are trying to achieve. Instead of telling us "I played this note and that squiggly note and then I hit the key that is next to the black one" you might instead ask us "how do you play chopsticks on the piano?". Explain in your words as if you were trying to tell your girlfriend what you are doing, of course she is not technical so you would say I am going to make that little thing there blink and turn on the lights when the dog barks. Of course we are technical and we can tell you how once you ACTUALLY tell us WHAT it is you are trying to do.

    As this is not an automated reply it may decide to stop responding.

    P.S. Hooray, I see you've posted some detail

    But sadly you are not getting to the point still

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 13:56
    Stefan, thanks for taking the time to write all of this and explain this ...



    Should this be the following?
    StefanL38 said...
    2) Set voltagelevel to 3.3V by using the command OUTA[noparse][[/noparse] IO-PinNumber] := 1
    instead of
    StefanL38 said...
    2) Set voltagelevel to 0.0V by using the command OUTA[noparse][[/noparse] IO-PinNumber] := 1


    If not, I apologize for asking, that's just how I understood the output? My knowledge of electronics is low, my knowledge of coding is intermediate, but I'm new to spin.


    My ultimate goal is to simulate sensor output of an automobile pressure sensor. When the ignition is "on" but the engine is not running, it puts out ~1.65v, when it first starts running, it puts out ~1.85v, then it spikes up to ~2.05v as a pressure test as a solenoid is turning off, and then falls to oscillation between 1.4v and 1.59v. My project could also be how to produce analog voltages, because I have a feeling I'm going to have to tweak those values to get it to simulate correctly.


    In your example of the 4 pins

    00: 0.0V
    01: 1.1V
    10: 2.2V
    11: 3.3V

    If these are all output pins, why are 01 and 10 different, and why aren't they 1.65v?


    Thanks again for replying!





    StefanL38 said...
    Hello TurboSupra,

    all the IO-PINs of the propeller can do DIRECTLY are FOUR things:

    a) if configured as input by DIRA[noparse][[/noparse] IO-PinNumber] := 0

    1) READING in a "0"
    2) READING in "1"

    both by using the command INA[noparse][[/noparse] IO-PinNumber]

    b) if configured as output by DIRA[noparse][[/noparse] IO-PinNumber] := 1

    1) Set voltagelevel to 0.0V by using the command OUTA[noparse][[/noparse] IO-PinNumber] := 0
    2) Set voltagelevel to 0.0V by using the command OUTA[noparse][[/noparse] IO-PinNumber] := 1

    NOTHING else. They are DIGITAL ON or OFF nothing inbetween.

    If you want conversion from a digital value to analog voltages you need a resistorladder with MORE than one IO-Pin

    example
    two IO-Pins
    with two IO-pins you have four combinations
    00
    01
    10
    11

    with four combinations you can create the following analog voltages

    00: 0.0V
    01: 1.1V
    10: 2.2V
    11: 3.3V

    as the Propeller-chip is a 3.3V device which will deliver 3.3V as maximum

    What other poster meant by asking for details

    your voltages are not a self-purpose.
    I don't think you want to have a ridiculous present for your father
    a propellerboard creating a voltage of 1.40V and say to your father
    "look if you measure on THAT pin you get 1.40V on the Voltagemeter-display !!"

    You are doing something else much more senseful with this voltage 1.40V

    WHAT is it ???

    If you describe your WHOLE project you will get good advice and it will take only 3 or 4 postings until your thing is working
    If you go on in the same way as above it will take 30 or 40 postings until you got your thing working

    If your whole project is "I want to get familiar with the propeller and first I would like to create analog voltages "
    OF COURSE that's a project too !
    If you write something about your knowledge-level of electronics and programming you will get advice you can really use

    From what you have written so far I guess your knowledge-level about electronics and programming is rather low.
    that REALLY OK just clarifiy it.

    If you ask simple questions the "a-little-bit-advanced-newbies" here will be happy that they can answer on postings too
    So just ask

    best regards

    Stefan
  • SamMishalSamMishal Posts: 468
    edited 2009-10-09 14:11
    Turbo,
    Don't be discouraged. Just give us a good description of what you are trying to achieve and
    perhaps we can give you a better idea of how to go about it.

    Si prefieres escribir en espa
  • SamMishalSamMishal Posts: 468
    edited 2009-10-09 14:25
    Turbo,

    I see you have just posted a better description of what you want to do.

    As I understand it you want to do ANALOG VOLTAGE output.

    A resistor ladder is not really the best way to do this. BUT IT WORKS if you have enough
    resistors.

    The BEST WAY to do this is to use a counter with DUTY MODE. This gives you a VERY FINELY
    controlled ADC·with just a resistor and capacitor (for filtering).

    This is described VERY WELL in·the Propeller Education Kit book On Pages 127 to 134.
    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf

    This is the best and tidiest way to do a DAC with good control and you can get all the
    voltage levels you need. Read the pages and you should be able to do it easily. There are
    programs examples that you can adapt to your needs.



    Samuel
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 14:25
    Gracias Sam

    Mi espanol es no muy bueno tambien, como mi ingles. [noparse]:)[/noparse]

    Actualmente estoy saliendo con una chica de Colombia y ella me esta ensenando algunas



    Did you see my description in my previous post? Is that descriptive enough to make sense?





    SamMishal said...
    <SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt">Turbo,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com[noparse]:office:[/noparse]office" /><otongue.gif></otongue.gif>

    <SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt">Don't be discouraged. Just give us a good description of what you are trying to achieve and
    perhaps we can give you a better idea of how to go about it.<otongue.gif></otongue.gif>

    <SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; COLOR: black; FONT-SIZE: 10pt; mso-ansi-language: ES" lang=ES>Si prefieres escribir en espa
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 14:27
    Reading now, thank you very much, I may have some questions after reading, haha


    SamMishal said...
    Turbo,

    I see you have just posted a better description of what you want to do.

    As I understand it you want to do ANALOG VOLTAGE output.

    A resistor ladder is not really the best way to do this. BUT IT WORKS if you have enough
    resistors.

    The BEST WAY to do this is to use a counter with DUTY MODE. This gives you a VERY FINE
    controlled ADC with just a resistor and capacitor (for filtering).

    This is described VERY WELL in a Propeller Education Kit book On Pages 127 to 134.
    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf

    This is the best and tidiest way to do a DAC with good control and you can get all the
    voltage levels you need. Read the pages and you should be able to do it easily. There are
    programs examples that you can adapt to your needs.



    Samuel
  • SamMishalSamMishal Posts: 468
    edited 2009-10-09 14:42
    turbosupra said...
    Reading now, thank you very much, I may have some questions after reading, haha
    ASK AS MANY questions as you need....people on this forum ARE GREAT and sooner or later
    someone will have exactly the right answer for you.

    The only stupid question is the one that has not been asked......feel free to ask as much as you want.

    I hope the PEK book can help you....it is a good book if you have not read it you SHOULD from
    page1 onwards. You can dispense with the chapter 3, especially if you are using the Propeller Professional
    Development Board· (PPDB).....chapter three would not be needed if you have a PPDB or Propeller Demo Board (PDB).

    But all the other chapters should be an interesting read and EDUCATIONAL too.

    Regards

    Samuel
    ·
  • SamMishalSamMishal Posts: 468
    edited 2009-10-09 14:57
    turbosupra said...
    Actualmente estoy saliendo con una chica de Colombia y ella me esta ensenando algunas
  • turbosupraturbosupra Posts: 1,088
    edited 2009-10-09 15:34
    Ok, how does this look? Am I understanding this correctly? Is is redundant to define outa[noparse][[/noparse] 8] in each repeat statement?


    
    
    
    
    ' Test circuit for voltage values
    
    
    [b]var[/b]
      [b]long[/b] x
           
    
    [b]pub[/b] Pumptest
    
                                                                             
        [b]dira[/b][noparse][[/noparse]*1..7] := %0000000                                                      ' sets pins 1 through 7 to inputs
        [b]ina[/b][noparse][[/noparse]* 1]  := 0                                                               ' sets pin 1 to be an input for an rpm value
        [b]ina[/b][noparse][[/noparse]* 2]  := 0                                                               ' sets pin 2 to look for a ground signal input
        [b]dira[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 to an output
        [b]outa[/b][noparse][[/noparse]* 8] := 1                                                               ' sets pin 8 as an output of positive voltage
                                                                      
    
      x := 0
    
      [b]repeat[/b]
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] == 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] <> 0)                         ' while pin 1 is not receiving a pulsing ground signal and pin 2 does not receive a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := %1                                                       ' connect input pin 3 to output pin 8 and repeat until it receives a signal on pin 1
               [b]ctra[/b][noparse][[/noparse]* 8] := %00110                                                   ' sets control to single sided
               [b]frqa[/b] := 2_147_483_648                                                ' sets the frequency for 1.65v                        
    
        [b]repeat[/b] [b]while[/b] x := ([b]ina[/b][noparse][[/noparse]* 1] > 0) [b]AND[/b] ([b]ina[/b][noparse][[/noparse]* 2] == 0)                          ' while input pin 1 has a pulsing ground signal and pin 2 has a ground signal
               [b]outa[/b][noparse][[/noparse]* 8] := %1                                                  ' repeat until this input is greater than 0 and is receiving a ground
               [b]ctra[/b][noparse][[/noparse]* 8] := %00110                                                   ' sets control to single sided
               [b]frqa[/b] := 2_407_784_696.24                                             ' sets the frequency for 1.85v  
    
        [b]repeat[/b] [b]while[/b] x := [b]ina[/b][noparse][[/noparse]* 1] > 0 [b]AND[/b] [b]ina[/b][noparse][[/noparse]* 2] <> 0                              ' while pin 1 receives a pulsing ground signal, but pin 2 does not receive a ground signal
          
               [b]outa[/b][noparse][[/noparse]* 8] := %1                                                       ' connect output pin 8 to input pin 7 and pass the voltage value
               [b]ctra[/b][noparse][[/noparse]* 8] := %00110                                                   ' sets control to single sided
               [b]frqa[/b] := 2_069_393_333.527                                            ' sets the frequency for 1.59v      
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' keeps outa[noparse][[/noparse]* 8] the current frequency value for 500 milli seconds, then repeats endlessly until ina[noparse][[/noparse]* 1] = 0 
               
               [b]outa[/b][noparse][[/noparse]* 8] := %1                                                       ' connect output pin 8 to input pin 6 and pass the voltage value
               [b]ctra[/b][noparse][[/noparse]* 8] := %00110                                                   ' sets control to single sided
               [b]frqa[/b] := 1_822_107_337.69                                             ' sets the frequency for 1.4v
               [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])                                             ' keeps outa[noparse][[/noparse]* 8] the current frequency value for 500 milli seconds, then repeats endlessly until ina[noparse][[/noparse]* 1] = 0
                  
    
    
    

    Post Edited (turbosupra) : 10/9/2009 3:40:53 PM GMT
  • mparkmpark Posts: 1,305
    edited 2009-10-09 16:13
    You're still assigning to ina ("ina[noparse][[/noparse] 1 ] := 0") which DOES NOT DO ANYTHING.

    You can't set ina[noparse][[/noparse] 1 ], you can only read it. ina[noparse][[/noparse] 1] is 0 if the voltage on input pin 1 is less than approx. 1.6V, and 1 if the voltage is higher.

    What exactly is a "pulsing ground signal"?
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-09 16:25
    Hello Turbo,

    your codelines

        ina[noparse][[/noparse]* 1]  := 0                                                               ' sets pin 1 to be an input for an rpm value
        ina[noparse][[/noparse]* 2]  := 0                                                               ' sets pin 2 to look for a ground signal input
    
    



    make no sense at all.

    it's enough to code

        dira[noparse][[/noparse]*1..7] := %0000000                                                      ' sets pins 1 through 7 to inputs
    
    



    if you want to look for a ground signal you code

    if ina[noparse][[/noparse] 1] == 0
      'code that should be executed when IO-pin number 2 is low = 0V = ground
    
    



    if you want to look for a high-signal you code

    if ina[noparse][[/noparse] 1] == 1
      'code that should be executed when IO-pin number 2 is high = 3.3V
    
    



    the analog voltage higher than 0.0V and lower than 3.3V are created through the resistor-capacitor-filter
    this means you have this analog voltage ONLY at the OUTPUT OF THE RC-filter

    If you measure the voltage DIRECTLY at the IO-PIN you see a voltage that switches all the time between 0.0V and 3.3V
    the pulseontime to complete pulselength-time ratio defines the voltagelevel (but ONLY at the output of the RC-filter

    example:
    pulselength-time 10 milliseconds
    pulseontime 2 milliseconds

    voltage at the RC-filter output: 3.3V * 2 milliseconds / 10 milliseonds = 0.66V

    2/10 = 0.2
    3.3V *0.2 = 0.66V

    and to your last posting yes your calculations for the voltages are right.

    the analog voltages 1.4V or 1.85V or whatever will ONLY be available at the Output of the RC-filter
    like in the attached picture

    best regards

    Stefan
    1231 x 339 - 48K
  • SamMishalSamMishal Posts: 468
    edited 2009-10-09 16:45
    Hi Turbo,
    No...no....all this code is not right....
    You only need to set the Counter (ctra[noparse]/noparse) once and only once.
    How it works is like this:
    You set the CTRA[noparse]/noparse mode and Pin for the signal output· (ONLY ONCE)
    Now Depending on the voltage level you need
    ·· You set the Frqa to specify the DUTY (ie. voltage) Level
    ·· Set the Pin to output [noparse]/noparse]dira[noparse][[/noparse)

    Now the Pin will have a voltage as you have set it.
    If later you need to change this voltage level all you need to do is
    set the right value in Frqa.

    If you need to stop the voltage (i.e. 0) then set FrqA to 0
    To do the changes in voltage depending on some push-buttons etc. then
    you read these normally and act accordingly.

    See the program on page 131. It shows how you can make the pin have
    a voltage from 0 to 3.3 volts in steps of 3.3/256.

    Notice how the Ctra[noparse]/noparse is set only once. But also notice how FrqA is set
    inside the loop to go through the levels.

    ·
    Regards
    ·
    Samuel
    P.S. Also see bottom of page 129.
Sign In or Register to comment.