• AVR Freaks

Helpful ReplyHot!Force Feedback Tutorial: PIC18F4550

Page: < 1234 > Showing page 2 of 4
Author
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/05/22 06:11:20 (permalink)
0
https://drive.google.com/file/d/0B1JcotWbqdjRLU9FODdUaXd0TEE/view?usp=sharing
 
And here is a link to the original descriptor tool i used, from usb.org.
 
Both links point to my google drive space.
#21
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/05/28 04:53:08 (permalink)
+2 (2)
Jesus Christ the web is becoming so bad lately, or I-m just becoming old.  
Uploading 1 file on 1 server used to be a straightforward job.
 
anyway, that code in FORCE FEEDBACK JS.zip compiles correctly for PIC18F4550 and it has the correct report descriptor.
I am not able to load it into a chip for now, but I will over the weekend. 

Next week I will post , hopefully a finished code ( where you get 2 outputs on 2 pins each time a forcefeedback effect is being played by the pc simulation )
 
#22
vtrx
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2013/01/04 17:42:57
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/01 09:02:58 (permalink)
0 (2)
When i use a test program, like Fedit, the program crashes.
You know why?
#23
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/01 22:11:32 (permalink)
0
I use ForceTest and it works fine .
Altough i am not testing exactly the same code i posted here. 
If i remember right, i modified some values in the Linker File .lkr, and upped and moved arround some of the memory used by usb. 
I brougt back the pic programmer and i will soon upload the code in it and test it, and complete it. 

This is what i get with forcetest.exe
 
https://ibb.co/MfpQBzW
https://ibb.co/W6byx6m
https://ibb.co/ZGCHpbx
https://ibb.co/44ns4Cf
#24
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/13 11:58:54 (permalink)
0
vtrx
vtrx
When i use a test program, like Fedit, the program crashes.
You know why?


I am now working on making it work, and you were right, the force feedback programs stall.... i don't know why for now, but i'll figure it out.

The code i have in my old chip works, and the force feedback test programs do not stall.

I just have to remember what i did last time, 4 years ago....
#25
vtrx
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2013/01/04 17:42:57
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/13 14:37:30 (permalink)
0
I tried to find out the problem, but I didn't come to a conclusion.
I just discovered that the interface did not respond to all requests or does not respond with the number of bytes that the program expects, this causes the program to be paralyzed.
post edited by vtrx - 2020/06/13 14:42:49
#26
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/14 05:27:46 (permalink)
0
I found it, kinda.
Now i have to read the data at the correct point.
 
I was missing this in this code:
 
if(!HIDRxHandleBusy(lastOutTransmission))
{
lastOutTransmission=HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
}
 
To read the data that the host sends to the device, on EP 1.
 
for now i placed it inside the main loop, and i just read...  

The force test program now doesn't crash, but cannot create the effects ( we need to read the data correctly and initialize the data structures with it)


Making progress... Now i'm at the stage where i receive the set effect reports.

Meanwhile i modified some report id's in the descriptor and changed some code in main.
post edited by Coman - 2020/06/14 11:26:42
#27
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/17 11:26:22 (permalink)
+1 (1)
In progress ++
A lot of the reports defined in the report descriptor are sent over EP 1 ( endpoint 1 ), only a few are sent over EP0 as control transfers.

I am recovering the right sequence.
We are getting closer.
#28
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/20 04:06:54 (permalink)
+1 (1)
Update:
 Ladies and gentlemen, i present to you the GENERATOR OF ENDLESS SWEARING, also known as a broken switch construct:

switch(SetupPkt.W_Value.byte.LB) 
{
 case 0x10:// REPORT ID PID_BLOCK_LOAD_STATUS
    switch(SetupPkt.W_Value.byte.HB) // REPORT TYPE
    {
     case 0x01:// INPUT REPORT
     break;
     case 0x02: // OUTPUT, the host wants to send me the data
    break;
    case 0x03:// FEATURE, the host wants ME to send the data
         
    temporary[0]=set_get_effect_structure.PID_BLOCK_LOAD_REPORT.report_id;
temporary[1]=set_get_effect_structure.PID_BLOCK_LOAD_REPORT.effect_block_index; temporary[2]=set_get_effect_structure.PID_BLOCK_LOAD_REPORT.block_load_status; temporary[3]=set_get_effect_structure.PID_BLOCK_LOAD_REPORT.ram_pool_available;
USBEP0SendRAMPtr((BYTE*)&temporary[0], 4, USB_EP0_NO_OPTIONS);
     break;
   }
 
case 0x22:// REPORT ID PID_POOL_REPORT
    
 PID_POOL_REPORT[0]=0x22; // report ID
 PID_POOL_REPORT[1]=120; // RAM POOL SIZE 120
 PID_POOL_REPORT[2]=0; // ROM POOL SIZE 0
 PID_POOL_REPORT[3]=0; // ROM EFFECT BLOCK COUNT 0
 PID_POOL_REPORT[4]=2; //SIMULTANEOUS EFFECT MAX 2
 PID_POOL_REPORT[5]=0b10000000;
 
 switch(SetupPkt.W_Value.byte.HB) // REPORT TYPE
 {
  case 0x01:// INPUT REPORT
   break;
   case 0x02: // OUTPUT, the host wants to send me the data
   break;
  case 0x03:// FEATURE, the host wants ME to send the data
                                 USBEP0SendRAMPtr((BYTE*)&PID_POOL_REPORT, 6, USB_EP0_NO_OPTIONS);
      FFB_IS_INIT=1;
  break;
 }
break;
}

 
If you want, you can search for the error and have a laugh :)
 
that thing drove me crazy for some days...
 
 
State :  Correctly receiving the set reports,correctly answering with the pid_block_load_status.
            now the host is sending me the effect data, and i'm working on that, untill all the effects are created correctly and the effect parameters are stored in the pic ram.
 
in the next update i will be posting the code that receives and gets the effects configured. ( it might take 1 week if i can't do it by tomorrow)
 
------------------------------------------------------------------------------------------------------------------------------------------
update :
after some beers and head scratching, i've finished creating the effects . 
now the firmware is able to create the force feedback effects.
i still have to set up some of the data correctly ( now i'm overwriting some of the effect parameters )
 
firmware now hangs when the driver sends commands to start and stop effects, but it's normal since that part it's not done yet.
 
 
 
post edited by Coman - 2020/06/20 08:52:52
#29
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/21 13:54:52 (permalink)
+2 (2)
This will be the last update for a while.
The firmware is almost ready.


It sets up the effects, int receives and process the start and stop commands.
It uses timer1 and 3 to perform some sort of pwm on pin RA4
 
The I/O is configured : RA0-1 analog inputs / RA2/3/4 digital out
RA4 outputs a signal when a play effect is received from pc driver.

there is more work to do with the effects, and maybe change the way they are stored , accessed etc.
There is more work to do in the effect descriptors to make order in the values (min/max) of inputs/outpus etc
But it is a starting point from where to build/improve.
 
The code changed a lot since the first posts where i explained the data structures required etc, but the general ideea is the same, and i don't have time for now to go back and correct it.


Best regards to all of you
Coman Nutu
Romania

Lux Aeterna Luceat.
#30
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/21 14:07:59 (permalink)
0
https://youtu.be/HfyznYrlUnE
 
A video of the firmware working with force test
post edited by Coman - 2020/06/21 14:09:08
#31
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/21 14:18:18 (permalink)
+1 (1)
https://www.youtube.com/watch?v=YTD3d3JF9sg
A video of the firmware receiving force feedback data from a flight game  ( Warthunder )
#32
vtrx
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2013/01/04 17:42:57
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/06/21 15:51:22 (permalink)
+1 (1)
Excellent job!
#33
vtrx
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2013/01/04 17:42:57
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/09/01 02:32:28 (permalink)
0 (2)
UP!
#34
gpaolo
Starting Member
  • Total Posts : 81
  • Reward points : 0
  • Joined: 2011/02/22 15:43:15
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/09/23 14:10:19 (permalink)
0
Hi Coman,
first of all, congratulation for the project. I have spent the last two weeks reading USB documentation and Microchip libraries and… what a hell of a mess. I miss so much my usual UART...
 
 
I am trying to understand how the system work, I don't want to copy simply your code, but I would like to have it running as a starting point to try to decode all settings, descriptors, etc. 
Said that, I have a dsPIC33EP512MU810 demo board with USB interface and I am trying to port your code on C30 for that Platform. It is just a rough work, but I have managed to compile it all without errors. 
Only warnings… and a failure with the assembler. I was wondering if it is something that you have seen before.
 
So, I get warnings in the usb_descriptor.c file after line 974:
 
usb_descriptors.c:974: warning: excess elements in array initializer
usb_descriptors.c:974: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:975: warning: excess elements in array initializer
usb_descriptors.c:975: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:975: warning: excess elements in array initializer
usb_descriptors.c:975: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:976: warning: excess elements in array initializer
usb_descriptors.c:976: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:976: warning: excess elements in array initializer
usb_descriptors.c:976: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:977: warning: excess elements in array initializer
usb_descriptors.c:977: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:977: warning: excess elements in array initializer
usb_descriptors.c:977: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:978: warning: excess elements in array initializer
usb_descriptors.c:978: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:978: warning: excess elements in array initializer
usb_descriptors.c:978: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:980: warning: excess elements in array initializer
usb_descriptors.c:980: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:980: warning: excess elements in array initializer
usb_descriptors.c:980: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:981: warning: excess elements in array initializer
usb_descriptors.c:981: warning: (near initialization for 'hid_rpt01.report')
usb_descriptors.c:984: warning: excess elements in array initializer
usb_descriptors.c:984: warning: (near initialization for 'hid_rpt01.report')

 
I could not find anything specific for the C30, but I guess it is some problem with the descriptor declared size and the actual implementation?
 
Then the compiler is ignoring all addresses specified:
 
API.c:88: warning: absolute address specification ignored
API.c:101: warning: absolute address specification ignored

 
related for example to
 
#pragma udata USB_VARIABLES=0x500
#pragma udata usb6=0x600

 
Any idea on this?
 
Then I get these errors
 
API.c: In function 'API_STOP_EFFECT':
API.c:131: warning: array subscript has type 'char'

 
on functions like:
 
void API_STOP_EFFECT(char effect_off)
{
 EFFECT_ON_ARRAY[effect_off]=0;
 T3CONbits.TON=0; //Timer3 On bit
 T1CONbits.TON=0; //Timer1 On bit
 PORTAbits.RA2=0;
 PORTAbits.RA3=0;
 PORTAbits.RA4=0;
}

 
but I have the feeling that this is due to the fact that the original program was for a 8-bit microcontroller while here I'm on a 16-bit one. But it's not really important at the moment.
 
Now what is really stopping me is this error:
 
C:\Users\GIANPA~1\AppData\Local\Temp/ccZlIJw4.s: Assembler messages:
C:\Users\GIANPA~1\AppData\Local\Temp/ccZlIJw4.s:91442: Warning: changed section attributes for USB_VARIABLES
C:\Users\GIANPA~1\AppData\Local\Temp/ccZlIJw4.s:91442: Error: invalid attribute combination for USB_VARIABLES

 
I can't really figure out what the problem is. I would imagine that it is linked to the fact that it is ignoring the #pragma on USB_VARIABLE? But I can't understand why… 
Thanks for any help!
 
 
 
#35
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/09/23 21:58:10 (permalink)
0
Hi, i either have modified the linker file, and expanded some of the default memory on it so i could fit the data inside one section ( i don-t remember exactly why i had to do it, it has something to do on how the linker defines the ram sections kinda )
 
USB_VARIABLES should be a section inside the linker file at some address ( 0x500 or so..) , it has a starting point and a size.
Thus you have to modify that section in your linker file for the pic controller you are using.
 
OR i am switching
udata USB_VARIABLES=0x500
so it points to a new location and save the data in the new location, something like that.
 
those errors have something to do with the memory layout of the processor you are using.
 
I can-t help further because i don-t use (never used)16 bit processors
 
#36
Coman
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/11/06 14:56:29
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/09/23 22:22:30 (permalink)
0
I would port the code like so :
 
Find the microchip example for a joystick or a mouse ( the default working ones from the libraries for your pic )
then change only the report descriptor in that example and have it working. ( recognized by windows as a joystick with force feedback capabilities ).
 
The report descriptor has a size and it is specified somewhere. #define HID_RPT01_SIZE 0x507
 
once the default example with the new report descriptor works you can start to add the callback functions to respond to the forcefeedback requests.
 
The callbacks are defined in : void USBCheckHIDRequest(void)
 where you add :
 case GET_REPORT:
                USER_GET_REPORT_HANDLER();
            break;
        case SET_REPORT:
                USER_SET_REPORT_HANDLER(); 
            break;
 
and work from that point forward.
The most difficult part is actually the report descriptor itself ( how to build a correct one ).
 
 
#37
gpaolo
Starting Member
  • Total Posts : 81
  • Reward points : 0
  • Joined: 2011/02/22 15:43:15
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/09/24 02:54:25 (permalink)
0
I'm having problems in posting my reply… let's see if it is because of the attachments...
#38
gpaolo
Starting Member
  • Total Posts : 81
  • Reward points : 0
  • Joined: 2011/02/22 15:43:15
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/09/24 02:55:53 (permalink)
+1 (1)
Hi, sorry for replying only now, but Yesterday I stopped at 2AM and I had more than enough :D
I have managed to get it running at the end. 
Basically, C30 doesn't use the #pragma udata any more, from what I understood it does everything automatically. So I changed those lines with the __attribute__ statement and the compiler was happy.
Most of the other issues I had were due to the fact that the USB stack included in the libraries was a couple of versions newer than the one you had, and the one you had was missing some .h for the dsPIC33E microcontroller. So I had to mix them together… and that is never a good idea.
A lot of work of Winmerge, but at the end I sorted out the missing definitions and functions.
Last huge issue, clock settings. I missed one bit of settings from the demo code and the device was too slow.
At the end, success! Connected and talking---sort of.
 
This is what happens.

 
 
The connection looks normal, until the point where the device sends the descriptor. The content looks correct, the length corresponds to the size requested, although there are six extra zeroes at the end that are not present in the code. I´m not sure if this is normal or not. 
But after that, the PC send an abort and disconnect the device. On the microcontroller, the status of the USB is still CONFIGURED, so it seems like it didn´t even notice.
 
 
 
 
 
#39
gpaolo
Starting Member
  • Total Posts : 81
  • Reward points : 0
  • Joined: 2011/02/22 15:43:15
  • Location: 0
  • Status: offline
Re: Force Feedback Tutorial: PIC18F4550 2020/09/24 02:57:00 (permalink)
0
this was the image for the previous post...
 
edit---
images have been reduced. This is awful. Here is the link for the readable one:
https://www.dropbox.com/s...6xdfz3ay/usb1.jpg?dl=0
post edited by gpaolo - 2020/09/24 03:04:25

Attached Image(s)

#40
Page: < 1234 > Showing page 2 of 4
Jump to:
© 2020 APG vNext Commercial Version 4.5