Previous in Forum: Can a pelton turbine work with a francis turbine?   Next in Forum: Power Electronics
Close
Close
Close
7 comments
Rate Comments: Nested
Participant

Join Date: Mar 2008
Posts: 4

Interfacing joystick using a MCU (P18F8680)

03/25/2008 5:32 PM

hello

I am working on a class project that require interfacing a p18F8680 with a analog joystick.

what is happening is that I have a code that should configure Analog and digital ports... and all the necessary settings respectively. however, testing the digital port to determine the output which is expected . it is still at LOW this should have been adjusted accordingly in the software and the movement of the joystick in either direction .... I am sure that I have an error some place maybe i will include a copy of my code for viewing


#include<p18f8680.h>
#include<delays.h>


void main(void)
{
unsigned delay1;
unsigned delay;
TRISD=0x00;
TRISA=0x01;

ADCON0=0x01;
ADCON1=0x0E;
ADCON2=0xA6;
CCP2CON=0x0B;

ADCON0bits.GO=1; // set to 1

ADCON0bits.DONE=0;

while(1) // while loop
{
while(!(ADCON0bits.GO));

Delay1KTCYx(200);
delay=ADRESH;
delay1=ADRESL;



}


}

I will appreciate any input to this

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Power-User
Canada - Member - BC Born, Alberta Raised, Quebec (poutine) crazed... Engineering Fields - Aerospace Engineering - An airplane is just a bunch of beams... Hobbies - Model Rocketry - Had fun as a kid...fun stuff Hobbies - CNC - dreaming of cutting Engineering Fields - Control Engineering - PID ME!

Join Date: Aug 2006
Location: Montreal, CANADA
Posts: 368
Good Answers: 10
#1

Re: Interfacing joystick using a MCU (P18F8680)

03/27/2008 7:58 AM

If this is an exercise with assembly language...I'm not the one to ask. What you are trying to do is pretty straight forward though. I've only programmed in other languages and then used cross compilers to come up with the assembly. For little projects (under 2000 lines of assembly) I use the demo versions from www.mikroe.com which allow you to program in C, Pascal or Basic. Their libraries and IDE make things a lot easier if you're new to this.

There is some sample code on their website about how to make a voltmeter...the port setup used there for their analog port should be the very same as your joystick.

Knowing assembly is good for debugging and optimising. Anything coming out of a cross compiler isn't going to be the most efficient use of program space on the pics memory but most little projects are small in size and these microcontrollers are getting more and more memory as time goes on.

Good luck!

__________________
kkjensen
Register to Reply
Power-User

Join Date: Jan 2008
Location: Toronto, Canada
Posts: 302
Good Answers: 4
#2

Re: Interfacing joystick using a MCU (P18F8680)

03/27/2008 11:36 AM

while (1) {}

will never end.

__________________
Pineapple
Register to Reply
Anonymous Poster
#3
In reply to #2

Re: Interfacing joystick using a MCU (P18F8680)

03/27/2008 1:21 PM

will omit the while

Register to Reply
Anonymous Poster
#4
In reply to #3

Re: Interfacing joystick using a MCU (P18F8680)

03/28/2008 11:30 AM

Obviously this is in C language.

The while(1) loop is called a super loop and is an intentional never ending loop. This is where you put the code to make the MCU process changes and events...

Without knowing a lot more about the specifics of the application it will be difficult to help much with the coding. You have two options when it comes to processing I/O events: 1. polling in the super loop to check state and react to changes by code 2. using the MCU's interrupts to process changes using the interrupt service routines (generally a better solution than polling). Study up on the interrupts supported by the MCU and features your are using - refer to the MCU datasheets and MCU Family Manuals... Microchip has good documents which you can download from thier website... Might also want to look at some of the Microchip "sample" projects to see how others have approached a similar project..

Need to keep the while loop... (Unless you are using a RTOS)

Just my thoughts...

Register to Reply
Participant

Join Date: Mar 2008
Posts: 4
#5
In reply to #4

Re: Interfacing joystick using a MCU (P18F8680)

03/28/2008 12:33 PM

The whole idea about what I want to do is this: Use a analog voltage to be read by portA.

That is : if analog voltage is 3.5 then that voltage is changed to a digital value that will store the value on portD pin which in this case will be my digital I/O.

If analog is 5 v the Voltage is changed to a digital value and command is stored on PortD ect

for now I am having problem reading the analog voltage . if this is done the rest is easy

Register to Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#6

Re: Interfacing joystick using a MCU (P18F8680)

03/30/2008 5:07 PM

Check that you have variable voltage at the input to your A/D converters or where the signals come in from the joystick. You might need a pull up resistor or something to make it play. Also check that the switches on the joystick work too while you have the voltmeter out. Could it be a hardware problem??

Register to Reply
Participant

Join Date: Mar 2008
Posts: 4
#7
In reply to #6

Re: Interfacing joystick using a MCU (P18F8680)

03/30/2008 10:19 PM

Hello

Thank for your comments and insights.. I have gone and test the variable voltages, and it turns out yes there is a variable voltage. Now there is a voltage change on AN0 which is my A/D Pin . Sofwarewise I want to read the voltage on the AN0 to determine the Robot movement. I want to be able to test the voltage level in my program code by reading ANO

.....

Register to Reply
Register to Reply 7 comments
Copy to Clipboard

Users who posted comments:

Anonymous Poster (2); hricks (2); kkjensen (1); Pineapple (1); Sciesis2 (1)

Previous in Forum: Can a pelton turbine work with a francis turbine?   Next in Forum: Power Electronics

Advertisement