When I run my code, should it work?
turbosupra
Posts: 1,088
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?
Post Edited (turbosupra) : 10/9/2009 12:41:09 AM GMT
' 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
Comments
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?
Post Edited (turbosupra) : 10/9/2009 3:17:37 AM GMT
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
I want is equal to, so I guess I want == ?
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*
Post Edited (turbosupra) : 10/9/2009 4:16:53 AM GMT
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
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*
The rest of your program will not run after the first repeat block.
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
@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?
P.S. I've run out of time for now, maybe someone else can assist you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
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
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
this code is trying to assign a value 0 to an Input pin..... will not work....
Regards
Samuel
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
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?
or this?
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*
Should this be the following? instead of
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!
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
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
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?
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
·
Post Edited (turbosupra) : 10/9/2009 3:40:53 PM GMT
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"?
your codelines
make no sense at all.
it's enough to code
if you want to look for a ground signal you code
if you want to look for a high-signal you code
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
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.