12 bits HID Joystick

General discussion on mikroC.
Post Reply
Author
Message
iNoxxam
Posts: 3
Joined: 03 Nov 2009 20:29

12 bits HID Joystick

#1 Post by iNoxxam » 03 Nov 2009 20:36

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?

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

#2 Post by drdoug » 03 Nov 2009 22:33

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.

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

#3 Post by w7ami » 04 Nov 2009 04:20

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

iNoxxam
Posts: 3
Joined: 03 Nov 2009 20:29

#4 Post by iNoxxam » 06 Nov 2009 22:50

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.

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

#5 Post by drdoug » 06 Nov 2009 23:25

iNoxxam wrote:It's a bit wierd but it works.
HAHAHAHAHA

iNoxxam
Posts: 3
Joined: 03 Nov 2009 20:29

#6 Post by iNoxxam » 07 Nov 2009 17:06

Don't you agree? ^^

Mince-n-Tatties
Posts: 2780
Joined: 25 Dec 2008 15:22
Location: Scotland

#7 Post by Mince-n-Tatties » 07 Nov 2009 20:58

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:

codepleb
Posts: 14
Joined: 14 Sep 2008 07:41
Location: Australia

Re: 12 bits HID Joystick

#8 Post by codepleb » 06 Jul 2010 13:23

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

NuMcA
Posts: 37
Joined: 24 Dec 2009 17:08
Location: Athens, Greece
Contact:

Re: 12 bits HID Joystick

#9 Post by NuMcA » 17 Jul 2010 08:16

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?
My simulation cockpit and other projects: www.numca.grImage

w7ami
Posts: 111
Joined: 21 Aug 2008 00:08
Location: Idaho

Re: 12 bits HID Joystick

#10 Post by w7ami » 17 Jul 2010 23:53

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

NuMcA
Posts: 37
Joined: 24 Dec 2009 17:08
Location: Athens, Greece
Contact:

Re: 12 bits HID Joystick

#11 Post by NuMcA » 18 Jul 2010 00:05

I am a few steps away from really understanding how this works.. But i will get there.. "Baby steps"! :)
My simulation cockpit and other projects: www.numca.grImage

Post Reply

Return to “mikroC General”