Page 1 of 1

12 bits HID Joystick

Posted: 03 Nov 2009 20:36
by iNoxxam
Hello.
I made a 8 bits joystick with a PIC18F4553, and now I'd like to convert it in a 12 bits one, in order to use the ADC at its best. It perfectly worked. I modifyed my descriptors, and set my logical maximums to 4095 instead of 255, and used

Code: Select all

write[0]=Adc_Read(0);
instead of

Code: Select all

write[0]=Adc_Read(0)>>4;
, but it doesn't works. Values displayed in the Windows's game controllers pannel are wrong. Is there something else to do to tell MikroC it's 12 bits values or am I wrong somewhere else?

Posted: 03 Nov 2009 22:33
by drdoug
If you are only using the upper 8 bits of the value, I do not see why you would get any benefit from using a 12 bit ADC?

I am trying to understand USB but I am not there yet.

BTW ADC read is a 10 bit value. Did you change the justification on the value or bit shift it? Maybe try a 2 bit shift instead of 4.

Posted: 04 Nov 2009 04:20
by w7ami
Dr Doug is correct. The ADC on the 4550 is 10 bit not 12. The USB interface is 8 bit so to send a 10 bit number you have to divide it into two 8 bit bytes, low byte first followed by the high byte. This is not as hard as it sounds since the data from the ADC is contained in two bytes, ADRESL and ADRESH. Put them into your transmit buffer and repeat for as many words of ADC as you need to send. Then send the buffer.

Terry

Posted: 06 Nov 2009 22:50
by iNoxxam
Yes, I agree, 4550 has 10 bits ADC. But I use 4553 which has 12 bits ADC.

But I've found my mistake. To send datas, you must first send the 8 lower bits, then, in the second byte sent, you must have the four highest bits of the first value as the four lowest bytes, and the four lowest byts of the second value as the four highest. It's a bit wierd but it works.

Posted: 06 Nov 2009 23:25
by drdoug
iNoxxam wrote:It's a bit wierd but it works.
HAHAHAHAHA

Posted: 07 Nov 2009 17:06
by iNoxxam
Don't you agree? ^^

Posted: 07 Nov 2009 20:58
by Mince-n-Tatties
Hi iNoxxam

life does not have to be so complex...

you have a 12bit ADC, this is broken down into 2 x 8bit registers

Upper Byte = ADRESH
Lower Byte = ADRESL

both these registers are populated with the new ADC read value and are ready to be used directly after ADC conversion has completed.

all you need to do is send each of these register bytes to your PC program where you can reconstruct them into a 12bit value. it makes no difference which order (ADRESL, ADRESH or ADRESH, ADRESL) you send them to your PC so long as you send them in the order your PC program expects to see them and before the next ADC conversion starts.

so...

Loop:
do ADC read
send ADRESH
send ADRESL
goto Loop:

Re: 12 bits HID Joystick

Posted: 06 Jul 2010 13:23
by codepleb
I've recently implemented an 8 bit USB HID joystick using the 18f4550 - and would like to change the throttle, X and Y axis from 8 bit to 10 bit.

Do you just need to split the 3 x 10 bit ADC results across 4 x 8 bit bytes?
i.e. :
1st byte = lower 8 bits of throttle ADC result
2nd byte = top 2 bits of throttle ADC result and lower 6 bits of x-axis ADC result
3rd byte = top 4 bits of x-axis ADC result and lower 4 bits of y-axis ADC result
4th byte = top 6 bits of y-axis ADC result and next 4 bits of whatever is next....(POV/switches..)
and so on..with suitable packing bits to get 5 bytes overall.

Assuming I have made appropriate changes to the HID descriptor is there anything else I need to do to ensure the correct data goes to the PC?

Regards,

CodePleb

Re: 12 bits HID Joystick

Posted: 17 Jul 2010 08:16
by NuMcA
These means that the PC needs an updated driver or extra software to re-construct the 12-bit/10-bit data? Or is there a specific HID descriptor that does it for us?

Re: 12 bits HID Joystick

Posted: 17 Jul 2010 23:53
by w7ami
NuMcA wrote:These means that the PC needs an updated driver or extra software to re-construct the 12-bit/10-bit data? Or is there a specific HID descriptor that does it for us?
This is taken care of by the descriptor table that you must write. The descriptor table tells the host computer what to do with the data that it receives.

Frankly it is easiest to just do what Mince-n-Tatties has already suggested.
Loop:
do ADC read
send ADRESH
send ADRESL
goto Loop:
And just set your descriptor tables to send the ADC data as 16 bits of data. Works for me.

Terry

Re: 12 bits HID Joystick

Posted: 18 Jul 2010 00:05
by NuMcA
I am a few steps away from really understanding how this works.. But i will get there.. "Baby steps"! :)