1. 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 Download Package Now!
  2. 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
  3. 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 here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

Pic Controlled FFB Wheel

Discussion in 'DIY peripherals' started by Marsniper27, May 16, 2018 at 18:14.

?

Are you interested in seeing the code?

This poll will close on May 30, 2018 at 18:14.
  1. Yes

    100.0%
  2. No

    0 vote(s)
    0.0%
  1. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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 at 17:51
  4. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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 at 19:52
  5. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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 at 17:49
  6. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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 at 20:58
  7. noorbeast

    noorbeast VR - The Next Generation Staff Member Moderator SimTools 2.0 Beta Tester

    Joined:
    Jul 13, 2014
    Messages:
    10,553
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    84,164Coins
    Ratings:
    +7,102 / 33 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  8. Marsniper27

    Marsniper27 New Member

    Joined:
    Apr 19, 2018
    Messages:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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:
    9
    Location:
    NB, Canada
    Balance:
    187Coins
    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:

Share This Page