Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Odd Problem With Old EDU Bot (http://www.chiefdelphi.com/forums/showthread.php?t=45064)

wun 06-03-2006 00:44

Odd Problem With Old EDU Bot
 
Hey,
I'm having a really strange problem with the old EDU controller (I think two years ago -- the first one to use a PIC processor and it needed an external RC controller). I've pulled it out to use on an un-related project, but the digital inputs don't seem to be working.
I've initialized them properly:
IO1 = IO2 ... IO8 = INPUT;
I've turned off analog:
Set_Number_Of_Analog_Channels(NO_ANALOG);
I've set the rest of the pins to output:
IO9 = IO10 ... IO16 = OUTPUT;
rc_dig_out09 ... rc_dig_out16 = 0;

Then when I check the values of the pins:
printf("rc_dig_in01: %d ... rc_dig_in08: %d\n", rc_dig_in01 ... rc_dig_in08);
I get:
257 257 257 257 0 0 0 0

Things get stranger. If I ground input 1, the output becomes:
1 257 257 257 0 0 0 0

And grounding other pins change random values (pin 4 changes value 2 from 257 to 256, etc).

EDIT:
I've figured out the pattern:
Grounding input 1 will cause the value of input 1 to be 1
Grounding input 2 will cause the value of input 1 to be 256
Grounding input 3 will cause the value of input 2 to be 1
Grounding input 4 will cause the value of input 2 to be 256
And so on...
If 16 is set as an input, it will cause the value of 8 to change from 1 to 0
Every input after 8 (9 and up) are 0 and I can't get 'em to change.

It dosen't seem to make any difference if I define none of the inputs as analog or all the inputs as analog (NO_ANALOG or EIGHT_ANALOG).

I'm using the default code from http://www.ifirobotics.com/edu-rc.shtml with the most recent firmware.

I have tried simple modifications to the default code (just printf("%d\n",rc_dig_in06); (where in06 defaults to an input) and similarly strange results have occurred.

Any advice would be greatly appreciated!
Thanks,
David

Alan Anderson 06-03-2006 07:32

Re: Odd Problem With Old EDU Bot
 
The %d format specifier wants to see an integer. The rc_dig_in## values are being passed to printf as chars. What you're seeing is the eight char values being printed as four int values.

To fix it, cast the switch values as ints.
Code:

rintf("rc_dig_in01: %d ... rc_dig_in08: %d\n", (int)rc_dig_in01 ... (int)rc_dig_in08);

wun 06-03-2006 12:44

Re: Odd Problem With Old EDU Bot
 
Quote:

Originally Posted by Alan Anderson
The %d format specifier wants to see an integer. The rc_dig_in## values are being passed to printf as chars. What you're seeing is the eight char values being printed as four int values.
To fix it, cast the switch values as ints.

Ah, of course! How could I forget. Actually, I suppose I forgot because I haven't programmed one of these things in years and my brain isn't at it's peak mental capacity at 1 am. Anyway, thanks for the help.


All times are GMT -5. The time now is 17:28.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi