1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Pic Controlled FFB Wheel

Discussion in 'DIY peripherals' started by Marsniper27, May 16, 2018.

?

Are you interested in seeing the code?

Poll closed May 30, 2018.
  1. Yes

    100.0%
  2. No

    0 vote(s)
    0.0%
  1. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    Hey everyone.

    I am new around here and found the forum while searching for info on making a FFB wheel.

    I see that MMos and the ST32 are a very popular choice for DIY wheels but I have decided to try to do it all from scratch. I am going to start off using some parts i already have laying around.

    I am using a Microchip Pic18F4550 to do initial testing. I already had one of these laying around and with using the Microchip Libraries for Application and the included joystick demo I have started developing the controller.

    Due to my current situation this is going to be a long and slow moving project but figured i would make a thread to show my progress.

    So far i have a breadboard setup with the pic and have the demo running on it. The pc recognizes the device as a HID Joystick. The initial demo only has one button configured which acts as the "x" button (xbox controller) and forces the joystick location to the top right limit. I have started modifying the code to include input for all buttons defined in the demo.

    If anyone is interested in seeing info on the actual programming of the device i will gladly show how i am doing things.
    • Like Like x 1
  2. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    Ok for those who would like to play along I am using MPLAB X (http://www.microchip.com/mplab/mplab-x-ide) and MLA v2017-03-06 (http://www.microchip.com/mplab/microchip-libraries-for-applications).

    I wont bother showing all the stuff that MLA has done for us and will just focus on the changes and modification I am making.

    To get to the USB-HID-Joystick demo it is a bit convoluted the default install address will put the project at: C:\microchip\mla\v2017_03_06\apps\usb\device\hid_joystick\firmware\picdem_fs_usb.x
    Since i am using the PIC18F4550 which is the chip on the older PIC FS USB demo board I am using that version of the example project. I do have and may switch over the the PIC18F45K50 which is whats on the newer demo board but the original is what i had on my breadboard already so that's what I'm using.

    FIRST EXCLAMER:
    I currently do not have an encoder so i am going to be doing initial work using a 10K potentiometer and using the PICs ADC act as the wheels rotation.

    Ok next post we will start working on some of the code. I am going to post as i go along so if changes are made later i will come back and update the relevant post.
  3. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    First we are going to start off by adding in all the buttons. Since the demo uses xbox controller button names already i am just going to continue with that. We will start by adding the definitions for all the buttons in the io_mapping.h header file.

    The example only has one button and one LED defined so we will add the rest.

    Button_X etc. is what we will use when calling our functions to check the status of the buttons. the Button_S2 etc. is going to align with our pin declarations.

    Attached Files:

    Last edited: May 17, 2018
  4. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    now that we have created our definitions we need to add them into the BUTTON type. In butttons.h we have the following only 2 definitions we will expand this to include all 14 of our buttons.

    Attached Files:

    Last edited: May 17, 2018
  5. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    Next we will need to implement the new buttons into our buttons.c file. currently this matches buttons_c_Original but we will have to add our buttons into our constants which is where we setup which port and bit(pin) the switch is on.
    In the Button_IsPressed we are setting up the test for if the button has been pressed. Button_enable we are setting the pins as inputs.

    For my pin allocation i decided to use ports B and D and start at PortB7 as this is pin 40 on my 40 pin pic and allows me to wire all buttons to the right side of the chip.

    Our BUTTON_IsPressed function is a bit quicker to do as we can simply copy and paste out the existing code to give us 12 instances and then rename the Sx to be 2-14.

    Like with our BUTTON_IsPressed function we can copy and expand out BUTTON_Enable function and relabel as needed.

    Attached Files:

    Last edited: May 18, 2018
  6. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    All our buttons are now setup so now we need to make them do something. for this we will be working with app_device_joystick.c and modifying the existing APP_DeviceJoystickTasks function and specificly the if statement controlling the usb message.

    This is just sending a message saying that a button "X" in this case is pressed and that the joystick is in the upper left extreme position. This is not very useful for a actual device so we will do a fair bit of modification to it.

    The first thing we need to do is make some way to check if a button was pressed. We are going to simply use a bool to tell us whether a button has been pressed. we will add this to the variable section of the file.

    Now down in out if statement again we have made a big change. We have not setup the wheel yet so we will just setup the buttons for now.

    The if statements are calling our BUTTON_IsPressed function to check each buttons pin to see if it has been pressed. If a button is pressed it will set the buttons value to true (1) in the usb message. if it is not true we set it to false (0) through the else if statement. As soon as a single button is registered as pressed the BUTTON_Pressed bool is set to true. This is so our final if statment "if(!Button_Pressed)" is only used if no button is pressed. this will ensure our inputs have been cleared out.

    Attached Files:

    Last edited: May 17, 2018
  7. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,465
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    144,626Coins
    Ratings:
    +10,741 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  8. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0

    Sorry about that. I will clean it up after. I am posting this as i do it so i could grab the original before i modified it. also had to get a few posts before i could attach files. I will work on copying all the posts into files tomorrow and will delete the original posts.
    • Like Like x 1
  9. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    I almost forgot an important part. We added the code to allow the buttons to be enabled but i did not add the function calls into the system.c file to actual use the code. here is the original and the modified system.c files. as you can see we simply copied the existing structure for all our buttons.

    Attached Files:

  10. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    Since i used part of the D port we need to comment out/remove one of the LED pin definitions from the led.h file as we are now using portD Pin 4 for one of our buttons. I choose to just comment out so i can easily modify to a different port if i want to implement more LEDs.

    Attached Files:

  11. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0
    So after wasting a bunch of time thinking i had an error in my ADC code it turns out i had a faulty pot. I got the wheel working and even tested it in dirt rally and while using a pot attached to a breadboard with no way of self centering itself is not enjoyable it did work. Now i am trying to increase the resolution of the wheel. Since the ADC on the pic 18F4550 is 10bit and the demo code only uses a 8bit command for the usb protocol I have to to divide the ADC output by 4 to match with the demos logical min-max range. I want to make full use of the ADC, from what i have found online what i have tried should be working but i have yet to get it too. I will post my Wheel header and source files when i have a chance (currently at work).

    Next step ;after i figure out this 10bit issue; will be to add in the pots for the break and gas pedal. I am using pots due to the low cost for prototyping but plan on using a loadcell for the break later. I only had 3 pots so i will need to get a replacement in order to have both pedals working at once.

    I need to save up some money to get my hands on a encoder and a decent motor to make a proper wheel but I might use a little DC motor to start trying to implement some FFB soon.

    UPDATE:
    I manged to figure out my issue and now have the joystick operating in full 16 bit mode scaling the 10bit ADC value.

    I was thinking today and have thought up a way to allow for quick and easy tuning of the wheel to match up with different games and vehicles in the game. My thinking is once in game in a car with the wheel homed and the input off set the wheel output to max left, user then turns the wheel to match the wheel on screen and presses X. the number of steps used to reach that position is captured and the process then repeats for the right. the device then calculates the scaling required to allow for a full turn based on the range input. I believe this will allow for a high accuracy of wheel position between onscreen image and actual wheel. The left and right extremes would be averaged to ensure equal rotation in both directions. Anyone have any thoughts on this?

    I want to do up the code for an encoder before i provide the wheel heard and source files but hope to get those done soon.
    Last edited: May 23, 2018
  12. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    12
    Location:
    NB, Canada
    Balance:
    347Coins
    Ratings:
    +2 / 0 / -0