PICcoder.co.uk Forum  


::post new topic::
<< Start < Prev 1 2 Next > End >>
Re:USB mouse connections 18F
Date: 2006/07/24 14:20 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
chib wrote:


I have just only 2 analog input so I suppose I must put : ADC_2ANA & 0xf



yeah, the "& 0xf" is a patch that I needed usinc MCC18 3.02 and a PIC18F4550... I think it was a bug in C libraries (though I'm not certain) and it was needed after some check in the datasheet. You may try with or without it!



If I plug the analog input in RA0 and RA1 (because RA2 and 3 are the Vref + and - on my PIC) to have my two values converted should I put :


ok.


SetChanADC(ADC_CH0);
Delay_uS(5);
ConvertADC();
while(BusyADC())
ClrWdt();
YVel=ReadADC();

SetChanADC(ADC_CH1);
Delay_uS(5);
ConvertADC();
while(BusyADC())
ClrWdt();
XVel=ReadADC();

my values will be YVel and XVel ?


Perfect. Note that the "ClrWdt()", though not strictly needed, has to be incorporated into the "while", thus NO ";" past thw while (BusyADC())

I made a mistake in my code!
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/24 14:22 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
chib wrote:
I missed something ...

Your code is for 8 or 10 bits ?


Hmm, it does not make any difference. The ReadADC() will return the correct value (for the given CPU), left or right adjusted depending on the flag you used in OpenADC (mine is right)

Post edited by: dariog, at: 2006/07/24 15:22
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/24 14:27 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
chib wrote:
hello , how do you build Delay_uS(5); ? (5 ms ?) because the compilator don't find this function.

Of course not

It's something very easy such as: (in microSeconds)

void Delay_uS(byte uSec) {

do {
Delay1TCY();
Delay1TCY();
Delay1TCY();
Delay1TCY();
ClrWdt(); // Clear the WDT
} while(--uSec);

}

probably you'll have to adjust it for your MCU Clock (usually 48MHz using Full Speed USB, that is what I use).
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/25 09:41 By: chib Status: Visitor  
 
thanks a lot,

The functions seems to work. My joystick is always moving but it seems that the sampling is not very fast ... What can I change to make it faster ?
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/25 09:58 By: chib Status: Visitor  
 
sorry for posting a lot of message, but i don't have the edit button ...

I have checked the value and i have seen that it is more than 8 bit but less than 16. isuposed it is a 10 bit conversion, how i can do a 8 bit ?
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/25 10:01 By: chib Status: Visitor  
 
hew sorry again ...

in the watch i have seen that :

00000110 10111101

the two bit in bold are always at 1 !!

why ?
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/25 11:45 By: chib Status: Visitor  
 
hum ....

I am stupid ... for a 10 bit i hav defined an 8 bit number ....

So the pb with the 1 is solved ....
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/26 14:08 By: chib Status: Visitor  
 
hello it's me (again)

for the ten bit I dived by 2 and then by 2 and it works !

so I have a working A/D converter, I have another pb but it is different, i will make a new thread tomorow

see ya !
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/26 20:27 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
Hi Chib, sorry, I was not online...

but I see you did succed! very good!!

To convert 10 bits to 8, you can divide by 4 or shift twice to the right i.e. XVel >>= 2;

To make it faster, well... usually that should not take longer than some uSecs... if I'm not wrong.
How often are you calling the conversion routine? I usually put it in a interrupt, or in the main loop via a divider (usually some 20..100 samples a sec is okay for a mouse)
reply | quote

Re:USB mouse connections 18F
Date: 2006/07/27 07:04 By: chib Status: Visitor  
 
Hi !

I have just put : YVel=ReadADC();
YVal=YVel/2;
Yval=YVal/2;

and XVel=ReadADC();
XVal=XVel/2;
Xval=XVal/2;

and it works so I don't edit ..... lol
I have 2 conversion, but if it's a ok for a mouse, it will be ok for my application !

Thanks a lot Dariog !! it was very helpful !

Now I have an other Pb but it's something else so I will make a new thread and I think you can help me .... (if you have some time, obviously)

(if somebody want my whole conveter i can post it)
reply | quote

Re:USB mouse connections 18F
Date: 2007/10/18 21:33 By: jdsanchez Status: Visitor  
 
hi!

im a kind of freshmen about USB with PIC, i donwloaded the code from Microchip bit it isnt work, i miss a file named "pic.h", somebody know where can i find it?

maybe im lookink at the wrong file at Microchip's page, but i dont know
someone please help me
reply | quote

<< Start < Prev 1 2 Next > End >>
::post new topic::