PDA

View Full Version : Help Needed Programming the Propeller in C



jdambri1
11-06-2010, 01:03 AM
I am new to the propeller, and was wondering if someone one could help me with basic programming using ICC v7. The main thing I would like help with is reading from pins. For instance I want to connect a photo-transistor. Thus I need to see if the there is a high input or low input. How would I do this. Appreciate any help

jazzed
11-06-2010, 01:42 AM
The main thing I would like help with is reading from pins.

This should work.



#include <propeller.h>

void main(void) {
long value = INA; /* read propeller pins into value variable */
for(;;); /* do nothing until next reset */
}

jdambri1
11-06-2010, 09:54 PM
Thanks a lot. That worked, now how would I go on input analog signal, like ADC conversion. Would the propeller just give me a 1 for anything other than 0 or would it give me actually hex value that i can compare to the voltage input.

jazzed
11-06-2010, 10:31 PM
Just reading a pin will give you 1 or 0 for each pin. Propeller does not have any built-in ADC, but a simple ADC can be built with 3 pins, some resistors and caps.

You should download this app note and look at ADC.spin with the Propeller Tool:
http://www.parallax.com/Portals/0/Downloads/appnt/prop/AN001-PropellerCountersv1.2.zip

The plain text description and schematic in ADC.spin should be enough to help you understand what to do (components should be kept as close together as possible).

The Propeller Tool converts Parallax font for the schematic into something readable. The Propeller Tool and other resources can be found here: http://www.parallax.com/ProductInfo/Microcontrollers/PropellerGeneralInformation/PropellerMediaPage/tabid/832/Default.aspx

jdambri1
11-06-2010, 10:56 PM
Once again thanks for the quick and extremely helpful respond. Thanks to you I think I have enough information to start my project. If I have any further questions I will make sure to post. Thank you very much.

jdambri1
11-07-2010, 01:23 AM
It seems that INA will save the value for all the pins, is there a way to access individual pins?

RossH
11-07-2010, 02:59 AM
hi jdambri1

Just mask off (or shift) the bits you don't want - e.g:



int bit0;
int bit1;

bit0 = INA & 0x00000001
bit1 = (INA & 0x00000002)>>1;Ross.

jdambri1
11-07-2010, 06:21 PM
Ok that makes perfect sense, I really appreciate the help.

jdambri1
11-09-2010, 05:03 PM
Hello , I know by now I must sound like a total newbie but I am still trying to learn the propeller's C commands. So to help make things clear I am currently using ICCV7 for propeller, but still debating whether I should use catalina instead. What would one advice. Second, if I use ICCV7 how would I go on having the propeller program interface with a terminal so that I can display information. Lastly does anyone know how to call specific cogs in ICCV7 , if so could i have an example code to reference to if not atleast the commands? I would truly appreciate any help.

jazzed
11-09-2010, 06:39 PM
There are examples for using ICCV7 here about half way down the page:
http://obex.parallax.com/objects/?o=9&ot=asc ...
You can use your favorite text editor to look at the ICC examples.

If you want to download Catalina and look at it's examples, go here: http://catalina-c.sourceforge.net/

Sadly there is no Propeller LMM GCC port :cry: We are working on a variation of GCC.
So for all the developers in the world spoiled by GCC, there is hope.

jdambri1
11-09-2010, 07:26 PM
Ok thanks , I been looking through the codes and saw that you have wrote a code for a C_TV_text and C_VGA version of it aswell, how ever being a new to it I was trying to explore the code to see what ports you used and couldn't figure out. So I was wondering if you happen to have a schematic that I could use as reference, if not it is ok.

jazzed
11-09-2010, 08:38 PM
The schematic containing TV and VGA circuits can be found in the Propeller Datasheet page 25 here: http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PropellerDatasheet-v1.2.pdf

You may have to adjust "pin" number in the tvText_start statement to match your hardware. The pin is the first pin number of the 4 contiguous pins used in the TV DAC resistor circuit.



void main(void)
{
int ii = 85;
int jj = 0;

tvText_start(20); // start TV

// ....
}

jdambri1
11-17-2010, 07:47 PM
Hey, I apologize for the frequent question but I have a question. So far I notice the propeller outputs 1.65V which is fine for most of my project but I was wondering if there is anyway to have it output 3V because I want to use a relay but the treshhold voltages is right in between. Is there an option to output 3V or will the best solution would be to use an op-amp ?

hover1
11-17-2010, 08:56 PM
The standard output of a Propeller chip is 3.3V.

http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PropellerDatasheet-v1.2.pdf

Where did you get the 1.65V from? Measurement?

Jim


Hey, I apologize for the frequent question but I have a question. So far I notice the propeller outputs 1.65V which is fine for most of my project but I was wondering if there is anyway to have it output 3V because I want to use a relay but the treshhold voltages is right in between. Is there an option to output 3V or will the best solution would be to use an op-amp ?

hover1
11-17-2010, 08:58 PM
How are you powering the circuit? If by battery, it seems it may be a little weak.

What do you have connected to your outputs?

Jim


I am having an issue with the propeller in which after a short period of time, the output would begin to fluctuate from 0 to 1 , I have tested basic codes to have it on, and it will remain on for about a minute or so and then start blinking. Have any of you had similar problems?

jazzed
11-17-2010, 08:58 PM
Do you have a loop in your program so that Propeller always has something to do? Without some kind of a loop at the end for example, random code can execute. On you previous question, it sounds like your pins are inputs unless you mean the VGA pins. How are you measuring the voltage?. You have to set pins to outputs to make them 3.3V or 0 without external circuits.

jdambri1
11-17-2010, 09:00 PM
Thanks, for the reply, and in fact after a little trouble shooting I connected it to a regulated power supply and it worked fine.

Mike Green
11-17-2010, 09:01 PM
Regarding 3V output. An unloaded Propeller I/O pin will put out approximately 3V. Once you begin to draw current from the I/O pin, the voltage will drop. This is true of any CMOS I/O pin on any microprocessor or microcontroller. They start out close to the supply voltage and this drops as more current is drawn out of the I/O pin.

Relays are generally current threshold devices. It may be that your relay simply draws too much current for operating. You need some kind of external transistor to switch on the relay. Look at Nuts and Volts Column #6 (http://www.parallax.com/tabid/272/Default.aspx) for examples of this for the Stamp. The same solutions work for the Propeller except that transistor base resistor values will be different (smaller) because of the different supply voltage.

Regarding the fluctuating output voltage. You probably have a problem with your power supply. It's really impossible to tell with the small amount of information you've provided. We really need a schematic and a listing of your program.

jdambri1
11-17-2010, 09:02 PM
I got the 1.65 voltage from the output of one of the pins, and I measured it with a simple multimeter, but it seems that all the trouble was cause for a weak battery. Now with the power supply I get close enough to 3.3 voltages. By the way I really appreciate your fast replies you are a life saver.

jdambri1
11-17-2010, 09:07 PM
Regarding 3V output. An unloaded Propeller I/O pin will put out approximately 3V. Once you begin to draw current from the I/O pin, the voltage will drop. This is true of any CMOS I/O pin on any microprocessor or microcontroller. They start out close to the supply voltage and this drops as more current is drawn out of the I/O pin.

Relays are generally current threshold devices. It may be that your relay simply draws too much current for operating. You need some kind of external transistor to switch on the relay. Look at Nuts and Volts Column #6 (http://www.parallax.com/tabid/272/Default.aspx) for examples of this for the Stamp. The same solutions work for the Propeller except that transistor base resistor values will be different (smaller) because of the different supply voltage.

Regarding the fluctuating output voltage. You probably have a problem with your power supply. It's really impossible to tell with the small amount of information you've provided. We really need a schematic and a listing of your program.


I apologize for the little information, but you were right it was a bad batter. Thanks again for your quick reply and advice , truly appreciate it.

jdambri1
11-17-2010, 09:55 PM
Hello once again I am having trouble with my output voltage. When I compile with ICCV7 using INA i get 1.65 range voltage. However if i use SPIN language I get a full 3.3 V. Why would be the reason for this.

Dave Hein
11-17-2010, 10:26 PM
1.65 volts is half of 3.3 volts. A multimeter will measure this voltage if the pin is toggling at a high frequency with a duty cycle of 50%. Measure the voltage in the AC mode, and if you don't get close to zero volts the pin must be toggling. Can you post your code? You have to set up DIRA also.

jdambri1
11-17-2010, 10:41 PM
1.65 volts is half of 3.3 volts. A multimeter will measure this voltage if the pin is toggling at a high frequency with a duty cycle of 50%. Measure the voltage in the AC mode, and if you don't get close to zero volts the pin must be toggling. Can you post your code? You have to set up DIRA also.

The following is the code I use to output to pin 17.

DIRA =1 << 17 ;
OUTA ^= DIRA;

jdambri1
11-19-2010, 05:05 AM
So is there a way to change the duty cycle in ICCV7 to get full 3.3v output, because i am able to get it using spin but not in ICCV7.

Nick Mueller
11-19-2010, 05:18 AM
When I compile with ICCV7 using INA i get 1.65 range voltage.

What is connected to the input?
And no, voltages are not compiler dependent. ;)


Nick

Dave Hein
11-19-2010, 01:30 PM
Maybe your C code is looping and the Spin code doesn't loop. If you post your code we'll probably be able to figure out what's wrong. Also, try changing the "OUTA ^= DIRA" to "OUTA |= DIRA". That will keep the pin high instead of toggling it.

jdambri1
12-04-2010, 08:18 AM
Hello I been working I got the above working right. Now my question is how would I read an RC signal from a ad592 temperature sensor. I was reading the data sheet and can't figure how, it seems it suppose to measure time it take to charge, and discharge.However, I am having a hard time how to approach this.

jdambri1
12-05-2010, 10:40 PM
how would someone read using the clock frequency.