Hot!Code Development Review, Critique and Recommendations for a Newbie to C and PIC

Author
meraviglioso
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2019/01/01 15:15:35
  • Location: 0
  • Status: offline
2019/02/11 20:36:13 (permalink)
0

Code Development Review, Critique and Recommendations for a Newbie to C and PIC

Firstly Moderators, if this is not the correct forum please feel free to move it.
 
This is not a broken code request.  The code does function as is. 
 
As many of you will recognize from a few of my recent posts, I am quite new to this environment and programming in C. I really struggled for a few weeks to the point where I almost gave up entirely, but I decided to push through. I feel like i have progressed quite a bit (a relative statement) since then, but I recognize that I have a long way to go.
 
I know the attached code is inefficient in many ways. I probably used the wrong methods and work arounds because my knowledge is limited. My background is in procedural programming using PLC's and primarily ladder logic.
 
So, I would like to ask some of you experienced programmers to review the project attached and provide some constructive feedback. Things like: "...use a structure here" or "...a for loop could help eliminate all of this repetitive code". Also, things like possibly using a timer interrupt service routine to provide a more consistent/stable sampling of the input data. These are all things I am not comfortable with but I think if I saw some applications with respect to code I have developed it would go very far.
Replies such as "read the manual" are not helpful and I would ask to keep to yourself. I have read the xc8 manual as well as gone through the datasheets for the PIC i am using and its peripherals multiple times. I also have "The Complete Reference, C" as a paper reference but I have found that there is no substitute for some time with an expert to set confusion straight.
I have read the xc8 manual as well as gone through the datasheets for the PIC i am using and its peripherals multiple times. I also have "The Complete Reference, C" as a paper reference but I have found that there is no substitute for some time with an expert to set confusion straight.
 
To anyone who wants to help out, I greatly appreciate your input and thank you in advance!
 
Platform Specifics: PIC18LF47K42, Explorer 8 Development Board, PICkit4, XC8 v2.0
Program Overview:
The project was partially developed using MCC. SPI, and some IO were deployed with MCC. There is a COUNTER Click module in port J32 of the Explorer board. This module's sample code was copied in from another project but is the code generated by MCC. Also included is the LCD code from the Explorer 8 sample code. I added some code to the COUNTER.c file to handle some of the functions that the original MCC code seemed to omit. I also made some modifications to it in order for it to work with the SPI code generated by MCC (pic10/12/16/18 library {not foundation services as is oem}). I created another header/C file named lcdSymbols, which defines the values to send some special characters to the LCD.
 
The steeringWheelInputAngle code uses the data from the COUNTER module to determine the steering angle in different data types as well as provides a variable to select how many turns to full lock. The steeringAngleLCD file takes data from the previously mentioned file and uses it to build out the LCD screen. The bottom row is used for heading tracking as a percentage of full lock (left/right) where the top row is a quasi "slew rate" which depicts how quickly the "wheel" is being rotated in each direction. The "steering wheel input" is being derived from a quadrature encoder attached to an old servo I had laying around.
See the video link in a post below.  The forum prevented me from saving this post with the link contained within.
post edited by meraviglioso - 2019/02/11 20:53:38
#1

10 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 16995
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/11 20:42:48 (permalink)
    +1 (1)
    Moderators never move anything here.
     
    #2
    meraviglioso
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2019/01/01 15:15:35
    • Location: 0
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/11 20:44:39 (permalink)
    0
    NKurzman
    Moderators never move anything here.

    Thanks NKurzman.
    I am struggling trying to get this entire post up.  It keeps preventing me from saving edits.  I may not be able to get the project attached.
    #3
    meraviglioso
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2019/01/01 15:15:35
    • Location: 0
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/11 20:47:12 (permalink)
    #4
    qhb
    Superb Member
    • Total Posts : 9170
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/11 20:52:57 (permalink)
    +2 (2)
    meraviglioso
    ...
    I am struggling trying to get this entire post up.  It keeps preventing me from saving edits. 



    You're fighting with the web server firewall.
    How to avoid errors when editing posts
     
    #5
    meraviglioso
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2019/01/01 15:15:35
    • Location: 0
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/11 20:57:11 (permalink)
    0
     
     
    Thanks qhb.  I will review that link.  I think I found the issues that were preventing me.  There were quite a few since the post was quite long.  The entire post (pretty much) is up now with the project attached.  The link to the video had to be added to it's own post.
    #6
    mlp
    boots too small
    • Total Posts : 686
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/13 07:20:20 (permalink)
    +1 (1)
    Before I say anything else, let me say Thank You for posting such a good description of the project you're working on and what type of assistance you are seeking.
     
    meraviglioso
    I also have "The Complete Reference, C"

    At least you will be warm during cold weather, as you have something to burn.
    It has for many years been the consensus of experienced C language users that the works of Herbert Schildt are ... a poor choice.
    See
         www.lysator.liu.se/c/index.html
    for plenty of useful documentation.
    Buy a copy of K&R2.
    post edited by mlp - 2019/02/15 10:53:12

    Mark (this opinion available for hire)
    #7
    meraviglioso
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2019/01/01 15:15:35
    • Location: 0
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/13 09:03:48 (permalink)
    0
    mark.pappin
    See&nbsp www.lysator.liu.se/c/index.html for plenty of useful documentation.
    Buy a copy of K&R2.


    Thanks mlp.  I honestly have been using it for simple verification of syntax however honestly, Google returns the answer i have usually much quicker.  Could you edit your link as it seems to be broken
    #8
    mlp
    boots too small
    • Total Posts : 686
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/15 10:54:15 (permalink)
    +1 (1)
    meravigliosoCould you edit your link as it seems to be broken

    I truly hate this forum software.

    Mark (this opinion available for hire)
    #9
    meraviglioso
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2019/01/01 15:15:35
    • Location: 0
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/15 11:00:30 (permalink)
    0
    mark.pappin
    meravigliosoCould you edit your link as it seems to be broken

    I truly hate this forum software.




    lol it can definitely be frustrating.  It took me over 15 edits to get the full post up with the links and attachments.  It got to the point where I was adding one sentence at a time and saving the changes.
    #10
    qhb
    Superb Member
    • Total Posts : 9170
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Code Development Review, Critique and Recommendations for a Newbie to C and PIC 2019/02/15 14:22:49 (permalink)
    #11
    Jump to:
    © 2019 APG vNext Commercial Version 4.5