Shop OBEX P1 Docs P2 Docs Learn Events
First C: C on the Propeller for Beginners - Page 2 — Parallax Forums

First C: C on the Propeller for Beginners

2»

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-09-13 10:26
    Mark Mara wrote: »
    My experience with C is that as I build an application at some point it starts doing some very wierd stuff. Errors move and warnings change when you insert debug statements. This usually means that I am stepping on memory somewhere.

    Is it possible to conclude that inserting debug statements could be moving the lines where your errors and warnings occur?

    GCC has hundreds of command line options. Most of them are processor specific. Many however are generic optimization flags or warning enable/disable flags.

    The most common command line options to be concerned with are in the Project Manager Compile and Linker settings tabs. I'm guessing a good service at this point would be to at least describe the flags that are used in the build process.
  • dgatelydgately Posts: 1,630
    edited 2013-09-13 10:37
    Roy Eltham wrote: »
    I personally prefer the Project mode (obviously), and can't stand the Simple view mode :P. I understand why it's there, but I don't have to like it or use it! Although, for the show I do switch back to that mode to check things.

    Yeah, the problem as experienced in the podcast is that SimpleView hides the project infrastructure while providing project-level actions (Open, Save, etc.). Atdiy's question about the difference between a project and its code file shows how SimpleView leaves out an important layer in that infrastructure. Hopefully, that comes to light for users that move on to multi-source file projects, eventually.

    But, I guess the idea is to get new users in a classroom environment up and running some code quickly and SimpleView is the "simplest" format to that end.


    Keep up the good work in these podcasts. Having several levels of expertise in the podcast certainly brings to light issues and allows discussion of C coding realities and solutions!

    dgately


  • jazzedjazzed Posts: 11,803
    edited 2013-09-13 11:38
    I guess Simple View is useful as a one file program tool. To me just a little more effort to teach Project View would be better.

    When modular library programming is being taught, students must use Project View ... before that is Ok too.The auto-include library feature should work fine with one file programs, but there is a point where creating libraries is useful.

    Create Project Library allows turning a project with multiple C files into a library that can be added to the Simple Libraries. Once a library is included with proper naming, it can be auto-included too.

    I strongly recommend version 0-9-43+ for library programming.
  • TymkrsTymkrs Posts: 539
    edited 2013-09-17 17:24
    Welcome to the 9th episode of FirstC! This is a short podcast series to help beginner coders learn how to program in C on the Parallax Propeller! This week we address more questions/comments on the Parallax forums and also cover some of the saving “issues” that Addie encounters. We then go into functions and how powerful they can become.

    Episode Link: http://www.tymkrs.com/shows/episode/firstc-episode-009/
  • jazzedjazzed Posts: 11,803
    edited 2013-09-17 21:03
    Some observations:

    Parameters for main are optional in C. Applications use "int main(int argc, char* argv[])", but it is not required by the standard.

    By not using void for a function without arguments, you lose function type checking.

    There is a half-second delay during the serial port startup. Sound's like that should be a one second delay.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2013-09-17 21:44
    jazzed,

    1. That's what I was trying to say without being too over the head of newbs. Sometimes I struggle with explaining things, because if I get too detailed in my explanation, then I have to explain several other things. In this case, I tried to just explain it enough for the newb listener. Often time in the long run (in later shows), we'll hit the topic again and explain it more.

    2. This is one I know, but never run into myself because in C++ foo() and foo(void) is the same thing and you still have type checking. Also, in the context of the Prop and Learn stuff it's not just not going to matter much.

    3. Good to know there is supposed to be a built in delay so you don't need one at the start of your program. We'll mention it in the next show. Thanks!
  • jazzedjazzed Posts: 11,803
    edited 2013-09-17 21:59
    Roy Eltham wrote: »
    j3. Good to know there is supposed to be a built in delay so you don't need one at the start of your program. We'll mention it in the next show. Thanks!

    It only works for simpletext functions like print and putLine. The standard serial driver that gives printf does not provide any start up delay.
  • TorTor Posts: 2,010
    edited 2013-09-18 07:06
    For the 'hello' example I would have set it up like so:
    static void hello(void)
    {
    ..
    }
    
    static void goodbye(void)
    {
    ..
    }
    
    int main ..
    
    the point being to use static functions as in the example all functions are local and private, and when that is combined with arranging the code bottom-up (code defined before usage) you get self-prototyping and don't have to explicitly add prototype declarations. You get smaller and well-organized source code. I only use explicit prototypes for local static functions if there's recursive or cross-calling going on, in other words almost never. I use non-static functions only when they're called from other source files, and in that case (i.e. always) the prototypes go into header files, not source files. In fact some compilers will give warnings if you add prototype declarations to source (.c) files, for example the Intel C compiler:
    remark #1419: external declaration in primary source file
    


    -Tor
  • David BetzDavid Betz Posts: 14,516
    edited 2013-09-21 09:57
    jazzed wrote: »

    It only works for simpletext functions like print and putLine. The standard serial driver that gives printf does not provide any start up delay.
    A startup delay is useful when you're using an IDE like SimpleIDE but it may not be what you want once you've finished developing your program and want to boot it directly from EEPROM. In that case, the delay serves no purpose other than slowing down program startup. Maybe it should be optional?
  • TymkrsTymkrs Posts: 539
    edited 2013-09-24 15:22
    Welcome to the 10th episode of FirstC! This is a short podcast series to help beginner coders learn how to program in C on the Parallax Propeller! This week we address questions/comments on the Parallax forums again and then go into functions and functions with parameters. Roy helps Addie with some of the tutorial code and we talk briefly about stack overflows!

    Episode Link: http://www.tymkrs.com/shows/episode/firstc-episode-010/

    Two Values: http://pastebin.com/eZ9w35hp
    Function with parameter Try 1: http://pastebin.com/WaS25kak
    Function with parameter Try 2: http://pastebin.com/qtsjUd2z
    Function with parameter Try 3!: http://pastebin.com/vEdmFXsu
    Function with parameter and Return: http://pastebin.com/e816qf3y
  • FrannyFranny Posts: 127
    edited 2013-09-30 09:58
    Thank you guys, This is awesome and really helps to understand the Prop chip, To me the Prop is like apple computers in the 90's, The best computers but without software or support giving gates the chance to swoop in and take over, Kinda like arduino... History repeats itself! Unfortunately most people don't care about 80MHz or 8 cogs, As long as they can understand and get it going fairly fast... I'm pretty sure though that now with C things are gonna change big time and will see more props at radioshack than arduinos whoo-hoo!
  • TymkrsTymkrs Posts: 539
    edited 2013-10-02 06:51
    Franny wrote: »
    Thank you guys, This is awesome and really helps to understand the Prop chip, To me the Prop is like apple computers in the 90's, The best computers but without software or support giving gates the chance to swoop in and take over, Kinda like arduino... History repeats itself! Unfortunately most people don't care about 80MHz or 8 cogs, As long as they can understand and get it going fairly fast... I'm pretty sure though that now with C things are gonna change big time and will see more props at radioshack than arduinos whoo-hoo!

    You're very welcome!! Glad you're learning more about the Propeller - <3. We're excited about how the focus of C will bring in new users! Do let us know if there's anything in particular you'd like us to cover as well.
  • TymkrsTymkrs Posts: 539
    edited 2013-10-08 16:14
    Welcome to the 11th episode of FirstC! This is a short podcast series to help beginner coders learn how to program in C on the Parallax Propeller! This week we gab about the Micromedic competition and then go into global variables and using multiple cogs with C. A big leap but with a little explanation, we learn a lot this week!

    Episode Link: http://www.tymkrs.com/shows/episode/firstc-episode-011/
    Global Variables: http://pastebin.com/index/huarhAU3
    Multi core Example: http://pastebin.com/0ZqPXKVW
  • jazzedjazzed Posts: 11,803
    edited 2013-10-11 11:24
    Episode 11 Feedback:

    Re: COGC mode speed and other modes.
    1. COG mode "COGC" programs will run "on the metal" without any interpreter. That means full speed of course.
    2. It is possible to run small functions (64 instructions or less) at full speed as well by tagging functions as __attribute__(fcache).

    Re: Volatile
    Volatile tells the Compiler not to optimize away some operation like read or write. It is often used in hardware device drivers.

    Re: print delays
    The print function does not actually have a startup delay. The delay is introduced one (and only one) time when simpletext/simple_serial is constructed at first program startup. And no, this will not be made optional. There should be no special print delays in multi-core code.

    Re: Warnings
    SimpleView programs do not enable warnings because that's what Parallax wanted.
    I've recently added code to new Project View projects to always enable warnings and will be in release 0-9-44+.

    Suggestions:

    Explain Show Map File (Project Manager right-click filename -> popup -> "Show Map File"

    Other multicore examples like use cognew to start a cog with PASM from a .spin or COGC from a .cogc file.
    Advanced 1.0 expert+ example: Use cognew to start a cog with in-line assembly (see simpletools fpucog.c).
    I'm available for forum Q&A if necessary.

    Episode 10 Feedback:
    Sorry, i fell asleep half-way through it ... it was late.
  • TymkrsTymkrs Posts: 539
    edited 2013-10-11 14:54
    jazzed wrote: »
    Episode 10 Feedback:
    Sorry, i fell asleep half-way through it ... it was late.

    LOL.
  • Hal AlbachHal Albach Posts: 747
    edited 2013-10-14 18:49
    Suggestions for a future Podcast:
    First of all, thank you for a great series on how to use C on the propeller. Even better, the discussions transcend beyond the propeller into the world of regular C. It has helped tremendously in my beginners understanding of how C works and why. Something I am hoping you will touch on in the near future is how to actually implement a C program that is made up of multiple .C files where functions are called across the multiple files. Some detail on how all the additional C files are incorporated into one functioning program would really be helpful. I remember reading on a Microchip forum where it was considered very bad form to actually #INCLUDE a .c file and that directive was meant for .h files. Any possibility we may hear you talk about this, with maybe some examples?

    Hal
    Seminole, Fl
  • TymkrsTymkrs Posts: 539
    edited 2013-10-15 11:31
    Hi Hal, I'll ask the senseis Whisker and Roy what they think :) I'm glad you've enjoyed the podcast and that it's helped your understanding! It's definitely helped mine haha, but I should hope so, otherwise I'm not asking the right questions! We'll address your comments next week but until then:

    Welcome to the 12th episode of FirstC! This is a short podcast series to help beginner coders learn how to program in C on the Parallax Propeller! This week we go into sensors that are available from Parallax such as the Ping distance sensor and PIR motion detector! We cover an example that has the PIR sensor triggering the Ping sensor. Episode Link: http://www.tymkrs.com/shows/episode/firstc-episode-012/
  • jazzedjazzed Posts: 11,803
    edited 2013-10-18 10:28
    Whipped cream?

    I don't favor the taste of pumpkin by itself, so to me whipped cream is absolutely necessary.

    Whipped cream ruins the taste of a White Mocha Grande' though.


    Here are some suggestions for getting around the noob == -vs- = problem:

    1) use if(readonly == variable) rather than if(variable == readonly) such that "readonly" is a constant or function.
    2) use != instead of == if possible.
  • TymkrsTymkrs Posts: 539
    edited 2013-10-22 15:48
    Welcome to the 13th episode of FirstC! This is a short podcast series to help beginner coders learn how to program in C on the Parallax Propeller! This week we’re looking at how to use the 2-axis joystick with continuous rotation servos! We go through Addie’s step by step method of try-try-again :).

    Episode Link: http://www.tymkrs.com/shows/episode/firstc-episode-013/
  • TymkrsTymkrs Posts: 539
    edited 2013-11-05 17:15
    Welcome to the 14th episode of FirstC! This is a short podcast series to help beginner coders learn how to program in C on the Parallax Propeller! This week we're looking at how to use the accelerometer and how to port Emic2 spin code into C using fdserial.h!

    Episode Link: http://www.tymkrs.com/shows/episode/firstc-episode-014/

  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-11-05 17:58
    Is there a Podcast as of yet for the Sharp IR Sensor? If not, is there a plan to do one? If it is here I have overlooked it.
  • TymkrsTymkrs Posts: 539
    edited 2013-11-05 18:09
    Not yet, but plan? Yes!
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-11-05 18:25
    Great. Thanks for the quick response. I will keep my eye out for it.
  • jazzedjazzed Posts: 11,803
    edited 2013-11-05 21:51
    I like your accelerometer LED idea. You should attach a ring of LEDs to Frisbee ... or a hat.
  • TalheaernTalheaern Posts: 7
    edited 2013-11-20 19:17
    Thank you for your podcast! I have been using the Prop chip for a couple of years and also enjoyed your First C podcast. I also have a beginners experience with C, so the First C podcast has been a great help.

    I have run into a problem. Have you tried to use the ramp feature of Servo.h, ramp does not effect the servos until the 2nd movement. See my code below:

    int main() // main function
    {

    while(1)
    {
    servo_setramp(11, 10); // Set up ramp for servos
    servo_setramp(10, 10);
    servo_angle(11, 900); // Servos facing forward
    servo_angle(10, 900);
    pause(2000);
    servo_angle(11, 1850); //Servos facing out
    servo_angle(10, 0);
    pause(2000);
    }
    }

    Hope the next podcast is soon!
  • TymkrsTymkrs Posts: 539
    edited 2013-11-21 05:36
    Hey - thanks for the feedback :) (And good idea Jazzed! - if only I could get it more responsive/faster) Glad you like the show! I haven't used the ramp function yet but I could certainly try your code and see what's going on.

    And we actually had some scheduling difficulties because of out of town visitors and with the holiday season, it may be a little bit before we have another episode - that just leaves me more time to get better code working!!
Sign In or Register to comment.