Converting a circulating mouse pointer to use a Potentionmeter

This is a discussion on Converting a circulating mouse pointer to use a Potentionmeter within the C Programming forums, part of the General Programming Boards category; I've bought a Development tool from Microchip which allows me to program my own USB interfaces. The Development board (PICDEM ...

Converting a circulating mouse pointer to use a Potentionmeter

I've bought a Development tool from Microchip which allows me to program my own USB interfaces. The Development board (PICDEM FS USB) from microchip has a potentiometer on board and comes with a number of Firmwares

I'm trying to integrate two pieces of code together so that i can get a mouse pointer to move from right to left using a potentiometer.
The first piece of code contains a program which orders the mouse pointer to move in circles (Although i have already been integrating the Potentionmeter components from the other code) The second is a program which determines the potentiometer position / resistance where feedback is provided in the form of an on screen graphical user interface.

I think i need to do something like do an A/D convert, then change the A/D result to a value between -127~127,for 10bit A/D using this formula to convert itA/D result)*256/1024-127.Then send this value to buffer[1] (The X Vector) in file user_mouse.c, and set buffer[2]=0.

But i am not sure how to write this into my code, and the structure which it requires...

ADRESL and ADRESH

Thanks for the link - i've seen the site...
The datasheet for this Microcihp does not explain how the Demo.c Firmware operates. However it does explain ADRESH and ADRESL which are high registers and low registers contained inside the PICs 10 bit A/D Module... It says that the AdresH and AdresL registers contain the result of the A/D conversion. When the A/D conversion is complete, the result is loaded into the adresh:adresl register pair, the GO/DONE bit (ADCON0 register) is cleared and A/D interrupt Flag bit, ADIF, is set.

I have found the following line of code in the Potentiometer Firmware supplied above :-

Code:

mInitPOT();

which upon checking was found to target the line in this header file:-

after looking at the 18F4550 Datasheet it revealed that 0x01 in the ADCON0 Register is the conversion status bit. 1 = A/D conversion in Progress, 0 = A/D Idle !!!
0x3C used in the ADCON2 register is for setting the A/D Acquisition Time Select Bits and the A/D Conversion Clock Select Bits... aparently...

But what code would i need to write to extract the value in ADRESH or ADRESL and correctly map this into buffer[1] ?

The function you mentioned just waits for a conversion.
ReadPOT(); is mis-named, it should be more like WaitForPOTConversion();

> signed char dir_table[]=
If you're trying to create mouse messages, then you need to understand that the mouse is sending small +/- numbers indicating the next small amout of motion - one for X and one for Y. With only one pot, you're only going to simulate one axis.

Also, in order to output a delta, you need to store the previous position as well.

> so shouldn't the code look something like this?
Yes, something like that.

> why do you think there is a need for the counter = 0x03;
Look at other examples in the same function, it's just a flag of some sort to manage what happens at the end. It's not necessary for what you're doing here.

> (256/1024)
Also known as x / 4

extern volatile near unsigned ADRES;
extern volatile near unsigned char ADRESL;
extern volatile near unsigned char ADRESH;
Use ADRES to get the full 16 bit value in one go.

> any ideas why would i need to do that???
Because the mouse delta is a much smaller number perhaps.
Maybe read up on the mouse protocol specification.

8 Bit device

How can there be a register that holds a 16bit value? The Microchip is 8 bits isn't it? All the registers work in 8 bits? although it does say that the A/D converter module is 10 bits in the datasheet! So wouldn't there be a problem with using the unsigned Adres; register ?

Though this is for COM Port communication - i imagine that the mouse protocol is still the same regardless of whether it is USB or other??? The website shows two types of protocol - a 5 bute mouse and a Microsoft Serial 3 byte mouse protocol.
I think the program has been written for microsoft serial communication! From the information it looks like the mouse program code that buffer[1] represents Byte 1 buffer[2] represents Byte 2 and buffer[3] represents Byte 3 !
- Is that correct?

If so then bits X6, X7 and Y6, Y7 would be left off wouldn't they?!
Thanks