Flip and propellerC language; RESOLVED

bbrienbbrien Posts: 347
edited 2020-07-09 - 03:45:21 in Customer Projects
I am lost, I tried to use a arduino and wrote a program with the help of some people on the forum. For some reason I am unable to get the PWM to a low enough value. I believe vthat the problem has to do with the operating frequency which is 16 mega Hz.I am now using the Flip board. I would like to get some examplkes using four digital inputs and four digital outputs,two for the enable pins and two dirrection pins of a UDN2993 driver chip. Arduino program is about 3700 bytes in size.
«1345678

Comments

  • Another Question or query: How do I initialize the input and output pins, I want to set Pins 0 through10 as inputs and pins 24 through 27 as output.
  • PublisonPublison Posts: 11,732
    edited 2020-01-25 - 09:27:03
  • bbrien,

    What is your project?
  • JonnyMacJonnyMac Posts: 7,007
    edited 2020-01-25 - 20:52:52
    I've attached a dual motor object that I've used in commercial camera pan/tilt controls. Speed control is from -100.0% to +100.0% in 0.1% steps. PWM frequency can be up to ~35kHz (motor loop is coded in Spin, hence the limitation). I have used it with other h-bridge chips. For each motor you need to define a PWM pin, a direction pin, and an enable pin. Again, it can control one or two motors. Two is the limit (per cog) because it uses the Propeller counter to create the PWM output pulse.

    Note: This is an object (library) -- not an application. You will attach this to your application code.
  • Genetix wrote: »
    bbrien,

    What is your project?

    My project is a telescope mount(Meade LX50) circa'2010'. It has two "DC clock motors" hooked to gearboxes turning the shafts. The azimuth axis has to rotate at a speed of approximately 1.5ms with a period of about28.5ms or a freq, of 50Hz.
  • also , how do I convert "0b00011111100000000000000000000000 "into hexadecimal.
  • @bbrien Take a peek here for an on-line tool: https://www.binaryhexconverter.com/binary-to-hex-converter

    For the methodology (which is really quite simple), there are a bunch of good vids on Youtube that cover the topic quite well.
  • JRoark wrote: »
    @bbrien Take a peek here for an on-line tool: https://www.binaryhexconverter.com/binary-to-hex-converter

    For the methodology (which is really quite simple), there are a bunch of good vids on Youtube that cover the topic quite well.

    Gave it a try but when I put in the # from my last post I got an invalid number message. What I am trying to do is set my I/O register.
  • An example program uses:
    int mask = 0x3fffffff; // creates an integer variable mask and initialize it as a bit mask with 1's in each place except for bit 30 and 31

    DIRA = mask // set direction register to the bit mask for outputs.
  • kwinnkwinn Posts: 8,614
    edited 2020-01-27 - 01:48:46
    Just break it up into groups of 4 bits starting with the 4 lsb's and convert each group to the equivalent hex digit as shown below.

    "0b 0001 1111 1000 0000 0000 0000 0000 0000 "
    Hex 1 F 8 0 0 0 0 0

    Hope it lines up when posted.

    Edit - Wishful thinking on having it line up, but I hope it gets the idea across.
  • JRoarkJRoark Posts: 564
    edited 2020-01-27 - 02:57:31
    Make sure you take off the leading “0b”. Thats just a cue to the compiler and not part of the number.

    Edit: confirmed. When I run your number (without the leading 0b) the calculator returns 1F800000.
  • JRoark wrote: »
    Make sure you take off the leading “0b”. Thats just a cue to the compiler and not part of the number.

    Edit: confirmed. When I run your number (without the leading 0b) the calculator returns 1F800000.

    Thanks for catching that omission. Another case of "everyone knows thatitis"
  • kwinn wrote: »
    Just break it up into groups of 4 bits starting with the 4 lsb's and convert each group to the equivalent hex digit as shown below.

    "0b 0001 1111 1000 0000 0000 0000 0000 0000 "
    Hex 1 F 8 0 0 0 0 0

    Hope it lines up when posted.

    Edit - Wishful thinking on having it line up, but I hope it gets the idea across.

    I tried out the numbers and the board loads successfully but I still have to test the input and the outputs. Now all I need to do is find out how to read four switched input pins with prop C.
  • Concerning checking the state of multiple input pins, what I need is four pins and four outputs ie:
    Pin1= output1+output3
    pin2= output2+output4
    pin3= output2+output4
    pin4= output1+output3
    Do I need to check them one after another or together at the same time. And if so how would I code This.
  • How do I code three Input Pins. I tried "int button = input(3,4,5); error
    "int button = input[3..5]; error
    "int button = input(3);
    int button = input(4); also error
    I cant find any examples in prop C.
  • JonnyMacJonnyMac Posts: 7,007
    edited 2020-01-28 - 20:49:26
    Spin is my go-to language for the Propeller, so you may get a better answer from someone else.

    If you're wanting to mimic this Spin code:
      result := ina[msb..lsb]
    
    ...you can add this function to your program:
    int readPins(int msb, int lsb)
    {
      int mask = 0xffffffff >> (31-(msb-lsb));
      
      return (INA >> lsb) & mask;
    }
    
    This will read a contiguous group of pins defined by msb and lsb. Again, Spin is my normal language, so one of the C experts may have a better solution.
  • Hope this helps.

    From the Propeller C reference simpletools.h
    Group I/O
    unsigned int get_states 	( 	int  	endPin,
    		int  	startPin 
    	) 		
    
    Get states of a contiguous group of I/O pins.
    
    This works the same as getState, but for a group of pins.
     It tells you the actual state of each pin, regardless of whether 
    it's a voltage applied to input or transmitted by an output.
    
    Parameters
        endPin	The highest numbered pin.
        startPin	The lowest numbered pin.
    
    Returns
        States value containing the binary bit pattern. The value for startPin should be in bit-0, next in bit-1, etc. 
    
    
    
  • I want to be able to test multiple pins , ie. read 4 input pins and control or toggle two output pins for PWM,(if( inpoinn2==0 ;^= outputpin2@1.5ms for 50hz freq.
  • If the pins are contiguous, the get_states() function will do that for you.

    What you do with that information is up to you. You will need a mask for each pin to test its state.
    #define MASK0 0b0001
    #define MASK1 0b0010
    #define MASK2 0b0100
    #define MASK3 0b1000
    
      int states = get_states(4, 1);
      if (states & MASK0) {
        // pin 1 is active
      }
      else {
        // pin 1 is not active
      }
    

  • I do not understand "JonnyMacs quote" does that work if the pins are in binary(0b00000000111111110000000000000000) Input pins are P3, P4, P5, P6 and output pins are P16 through P19 plus 4 more unreserved outputs.
  • If you want to take a snapshot of the current states of P3..P6, you would do this:
      pinStates = get_states(6, 3);
    
    If P3 and P4 were high, and P5 and P6 low, the value of pinStates would be 0b1100. Now that you have those states captured, you can act on them. I -- and I suspect others -- are still trying to suss out what you want to do with the input states.
  • bbrienbbrien Posts: 347
    edited 2020-01-30 - 05:28:27
    
    these input states will eventually turn on two output pins,one will be toggled in such a way as to produce a PWM pulse and the second will output either a one or a zero. the second pair of output pins will be similar. I wrote a small program that doesn't  build.
    
    #include "simpletools.h"
               #include "propeller.h"
    
              #define button1 input(3)
              #define button2 input(4)
              #define button3 input(5)
              #define button4 input(6)
    
              clkfreq:5000000
              clkmode:XTAL1
          
              int main()
               {
                 int mask = 0xff0000;
    
                 intfreq = CLKFREQ>>1;
    
                 DIRA = mask;
    
             while(1)
               {
                 int button1 = input(3);
                 if(button1 == 1)
                   {
                     high(17);
                     pause(200);
                     low(17);
                     pause(200);
                  }
                int button2 = input(4);
                if(button2 == 1)
                  {
                    high(18);
                    pause(200);
                    low(18);
                    pause(200);
                  }
                int button3 = input(5);
                if(button3 == 1)
                 {
                   high(19);
                   pause(200);
                   low(19);
                   pause(200);
                 }
                int button4 = input(6);
                if(button4 == 1)
                 { 
                    high(20);
                    pause(200);
                    low(20);
                    pause(200);
                  }
             }
         }
    

    Several Errors "expected declaration specifiers or "..." before numeric constant(2)
    I don't understand and how do I fix. Thank You
  • I can get it to build if I comment out the #define's, "clkfreq:5000000" and "clkmode:XTAL1", and change "intfreq" to "int freq".
  • bbrienbbrien Posts: 347
    edited 2020-01-30 - 19:53:03
    Intfreq is a typo, in the program it was "int freq". I still need the clkfreq and the clkmode
    to make the board run at 5MHz . How do I declare the variables without "#define. If you can show me a better way, I am all eyes.
  • You do not need to use the #defines to declare the button* variables. They are declared as int's later in your program.

    I'm assuming you're using SimpleIDE, so you would set clkfreq and clkmode by defining a new board type. You need to locate where boards.txt is on your computer, and edit it to add a new board type entry. You then need to create a *.cfg file containing the board information.

    On my Windows system, the board type files are located in the directory C:\Program Files (x86)\SimpleIDE\propeller-gcc\propeller-load. I added a custom.cfg entry to my boards.txt file, and I made a custom.cfg file based on the hub.cfg file. My files are in the attached zip file.
  • Already tried that but couldn't do it.
  • Did you try (from the propeller.h reference):
    #define clkset 	( mode, frequency ) 		
    Value:
    do { \
      _CLKFREQ = (frequency); \
      _CLKMODE = (mode); \
      __builtin_propeller_clkset(mode); \
    } while(0)
    
    Set clock mode and frequency.
    This macro is used to set the run-time clock mode and frequency. The clock mode and frequency are normally configured by the loader based on the user selected board type.
    Please see the Propeller Data Sheet for more clock information.
    Parameters
        mode	The 8 bit clock mode
        frequency	The 32 bit clock frequency
    Returns
        This macro will not return a value. 
    
    
  • clkset() looks like a good way to do it. I understand that adding a board type does take a bit more effort. You have to have admin rights.

    If you want to try changing the board types, type "admin" in the search field on the task bar, and then click on "Run as administrator". This will allow you to change the files in the propeller-load directory.
  • It looks difficult to me , _CLKFREQ = 5000000;
    _CLKMODE = XTAL1;
    _builtin_propeller_clkset( ); looks unknown to me, Do I put "xtal1" in the mode or what and where do I put all of This , Before or after the"int main()",
  • twm47099twm47099 Posts: 865
    edited 2020-01-31 - 00:28:53
    I'm not an expert but
    The statement #define clkset ( mode, frequency ) is a macro. You only have to enter the value for mode and frequency into the parentheses.

    The stuff under "value" is just what that macro does.
    So you need mode & frequency.
    First:
    clkfreq = the xtal frequency * the PLL value (1, 2, 4, 8, or 16)
    So if you want a frequency of 5MHz you need a xtal whose value is 5MHz / (one of the PLL values).

    So if your xtal is a 5MHZ crystal, you would use PLL1X.
    Then Clock mode = XTAL1 + PLL1X = 0b01101011 = 107
    from page 69 of the propeller manual or page 14 of the propeller data sheet.

    The frequency is 5000000.

    Try those.

    Note: the SimpleIDE Libraries are documented here:
    https://cdn.rawgit.com/parallaxinc/propsideworkspace/master/Learn/Simple%20Libraries%20Index.html

    The propeller manual is here:
    https://parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf


Sign In or Register to comment.