Shop OBEX P1 Docs P2 Docs Learn Events
Help Needed Programming the Propeller in C — Parallax Forums

Help Needed Programming the Propeller in C

jdambri1jdambri1 Posts: 17
edited 2010-12-05 15:40 in Propeller 1
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

Comments

  • jazzedjazzed Posts: 11,803
    edited 2010-11-05 18:42
    jdambri1 wrote: »
    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 */
    }
    
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-06 14:54
    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.
  • jazzedjazzed Posts: 11,803
    edited 2010-11-06 15:31
    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
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-06 15:56
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-06 19:23
    It seems that INA will save the value for all the pins, is there a way to access individual pins?
  • RossHRossH Posts: 5,519
    edited 2010-11-06 20:59
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-07 11:21
    Ok that makes perfect sense, I really appreciate the help.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-09 10:03
    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.
  • jazzedjazzed Posts: 11,803
    edited 2010-11-09 11:39
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-09 12:26
    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.
  • jazzedjazzed Posts: 11,803
    edited 2010-11-09 13:38
    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
        
    // ....
    }
    
    
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-17 12:47
    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 ?
  • hover1hover1 Posts: 1,929
    edited 2010-11-17 13:56
    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
    jdambri1 wrote: »
    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 ?
  • hover1hover1 Posts: 1,929
    edited 2010-11-17 13:58
    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
    jdambri1 wrote: »
    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?
  • jazzedjazzed Posts: 11,803
    edited 2010-11-17 13:58
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-17 14:00
    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 GreenMike Green Posts: 23,101
    edited 2010-11-17 14:01
    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 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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-17 14:02
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-17 14:07
    Mike Green wrote: »
    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 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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-17 14:55
    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 HeinDave Hein Posts: 6,347
    edited 2010-11-17 15:26
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-17 15:41
    Dave Hein wrote: »
    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;
  • jdambri1jdambri1 Posts: 17
    edited 2010-11-18 22:05
    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 MuellerNick Mueller Posts: 815
    edited 2010-11-18 22:18
    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 HeinDave Hein Posts: 6,347
    edited 2010-11-19 06:30
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-12-04 01:18
    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.
  • jdambri1jdambri1 Posts: 17
    edited 2010-12-05 15:40
    how would someone read using the clock frequency.
Sign In or Register to comment.