Go to Post You will find we are more talkative in about 5 1/2 weeks. ;) - mrnoble [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-02-2008, 19:59
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Printf prints only the first character

Hello,

I've been using printf to print out a menu to the terminal, so that I can interact with the program at run time. It has been working like a charm...until today.

I have this function that has been working great all along. Until I tried it today.

This is the function:
Code:
void PIM_Int_PrintPIDMenu(void) {
	//Print out the menu.
	printf("PID ADJUSTMENT MENU:\r\n");
	printf("Steering PID:\r\n");
	printf("P: %d / %d, I: %d / %d, D: %d / %d, Max I: %d\r\n",EEPROM_Read2Byte(EEPROM_ADDRESS_P_NUMERATOR),EEPROM_Read2Byte(EEPROM_ADDRESS_P_DENOMINATOR),EEPROM_Read2Byte(EEPROM_ADDRESS_I_NUMERATOR),EEPROM_Read2Byte(EEPROM_ADDRESS_I_DENOMINATOR),EEPROM_Read2Byte(EEPROM_ADDRESS_D_NUMERATOR),EEPROM_Read(EEPROM_ADDRESS_D_DENOMINATOR),EEPROM_Read(EEPROM_ADDRESS_I_MAX_PWM));
	printf("For P term:\r\n");
	printf("[a] Reset Num to 0 and Denom to 1\r\n");
	printf("[b]/[c] (Inc/Dec)rement Num\r\n");
	printf("[d]/[e] (Inc/Dec)rement Denom\r\n");
	printf("[f] Double Num and Denom\r\n");
	printf("For I term:\r\n");
	printf("[g] Reset Num to 0 and Denom to 1\r\n");
	printf("[h]/[i] (Inc/Dec)rement Num\r\n");
	printf("[j]/[k] (Inc/Dec)rement Denom\r\n");
	printf("[l] Double Num and Denom\r\n");
	printf("For D term:\r\n");
	printf("[m] Reset Num to 0 and Denom to 1\r\n");
	printf("[n]/[o] (Inc/Dec)rement Num\r\n");
	printf("[p]/[q] (Inc/Dec)rement Denom\r\n");
	printf("[r] Double Num and Denom\r\n");
	printf("[s] Refresh this menu (ALWAYS do before reading numbers!!!)\r\n");
	printf("Misc:\r\n");
	printf("[t]/[u] (Inc/Dec)rement I max PWM\r\n");
	printf("[v] Reset I max PWM to 0\r\n");
	printf("[w] Toggle anti-windup (currently %d)\r\n",EEPROM_Read(EEPROM_ADDRESS_I_ANTIWINDUP));
}
I should be getting each one's output in my terminal...but I get
Code:
PID ADJUSTMENT MENU:
Steering PID:
PF[[[[F[[[[F[[[[[M[[[
instead.

Has anyone seen this before? I'm seriously considering writing a homebrewn function to print each character independently...but I'd like to stay away from that route if at all possible.

Please help...
JBot
__________________
Aren't signatures a bit outdated?
  #2   Spotlight this post!  
Unread 07-02-2008, 20:19
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Printf prints only the first character

Have you added recent code that generates a lot of interrupts? You could be missing some now. Or maybe...

Your output is going crazy when you try to print your first variable. Is there something wrong with your variables? Is the linker giving you any warnings?


HTH
  #3   Spotlight this post!  
Unread 07-02-2008, 20:41
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: Printf prints only the first character

Quote:
Originally Posted by wireties View Post
Have you added recent code that generates a lot of interrupts? You could be missing some now. Or maybe...

Your output is going crazy when you try to print your first variable. Is there something wrong with your variables? Is the linker giving you any warnings?


HTH
I don't have many interrupts firing at all, and I haven't added any for quite a few builds. It looks like it is the variables making it stop working...and i've seen some pretty strange stuff involving my EEPROM_Read2Byte function (it was CRASHING the COMPILER... ) so maybe...

Code:
unsigned int EEPROM_Read2Byte(unsigned int arg_address) {
	//Return the parameter.
	return (EEPROM_Read(arg_address) * 0x100) + EEPROM_Read(arg_address+1);
}
See anything wrong? It's Kevin Watson's EEPROM code with my own function added for 2-byte variables...

Now, why don't we have a "beating head on brick wall" smiley?

JBot
__________________
Aren't signatures a bit outdated?
  #4   Spotlight this post!  
Unread 07-02-2008, 23:19
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Printf prints only the first character

Your last two parameters in the third printf() are single bytes. The %d specification wants to see two-byte integers. You are thus causing it to try to read more data than you've provided, which results in really really weird printing.

If those last two things are really single bytes, make the printf() happy by saying (int)EEPROM_Read(...). Otherwise, correct them to say EEPROM_Read2Byte(...).
  #5   Spotlight this post!  
Unread 08-02-2008, 13:46
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Printf prints only the first character

The last two calls are to routines that return single bytes... but the compiler automatically passes these as ints to the printf - for readability you can and the (int) or (unsigned int) case, but it won't change the code generated.
Code:
 

  RCALL EEPROM_Read                      
  MOVF POSTDEC1, F, ACCESS   ; pop the arg off  stack        
  MOVF POSTDEC1, F, ACCESS   ; pop 2nd byte of arg off stack
  MOVWF POSTINC1, ACCESS    ; push returned char onto stack
  CLRF POSTINC1, ACCESS        ; push 2nd byte of zeros onto stack
Try commenting out the printf with the 7 arguments. If that works, add back in arguments one at a time, i.e.

printf( "P: %d / %d\r\n", EEPROM_Read2Byte(EEPROM_ADDRESS_P_NUMERATOR),EEPRO M_Read2Byte(EEPROM_ADDRESS_P_DENOMINATOR)

Could be running up against variable stack limit (shouldn't be) or formated printf buffer limit...

Actually, I'll take that back... could be a variable stack limit depending on how the printf -> vprintf -> vfprintf -> ... is done vis-a-vis copying stack arguments.

Debug steps are the same, reduce the printf. Could change this into a series of printfs and leave off the \r\n until the last one in the series too.
  #6   Spotlight this post!  
Unread 08-02-2008, 19:49
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: Printf prints only the first character

OK, new strangeness...

I used to see this glitch only on lines that had variables in them. I now am getting single-character output from a line with no variables.

It always prints the first token; if I have a %d first thing, the number is printed, but often the rest of the string is absent.

Code:
PRESET #1 EDIT:
S-1
Wrist goal: 2
That's my output from this snippet:
Code:
	int loc_temp;
	printf("\r\nPRESET #%d EDIT:\r\n",(int)arg_preset);
	loc_temp = EEPROM_Read2ByteSigned(EEPROM_ADDRESS_PRESET_BASE + (arg_preset-1)*EEPROM_PRESET_LENGTH + EEPROM_PRESET_OFFSET_SHOULDER);
	printf("Shoulder goal: ");
	printf("%d\r\n",loc_temp);
	loc_temp = EEPROM_Read2ByteSigned(EEPROM_ADDRESS_PRESET_BASE + (arg_preset-1)*EEPROM_PRESET_LENGTH + EEPROM_PRESET_OFFSET_WRIST);
	printf("Wrist goal: ");
	printf("%d\r\n",loc_temp);
It seems to think it's done with the string. There are only Kevin Watson's ADC interrupts firing, and I have it set at 200Hz, so that should not be my problem. It also seems to be value-dependent. When I have negative values for the shoulder goal, it does print them, but the line before it gets truncated to first character.

This is getting stranger by the second.

JBot
__________________
Aren't signatures a bit outdated?
  #7   Spotlight this post!  
Unread 08-02-2008, 23:44
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Printf prints only the first character

Try things one at a time. You can't easily deduce which line is causing the problem. The output is buffered so sometimes its a bit difficult to correlate the cause of the problem with what actually makes it out the serial port.

Are you sure you are not reading from places in memory that are not in the EPROM? Try printing out the parameters to the EEPROM_Read2ByteSigned function.

Maybe the serial buffers are overflowing, are you checking the return values of printf?

HTH
  #8   Spotlight this post!  
Unread 09-02-2008, 08:05
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: Printf prints only the first character

Quote:
Originally Posted by wireties View Post
Try things one at a time. You can't easily deduce which line is causing the problem. The output is buffered so sometimes its a bit difficult to correlate the cause of the problem with what actually makes it out the serial port.
I've been doing things slowly, one at a time, but I haven't documented every step because I've been kinda busy...

[QUOTE}Are you sure you are not reading from places in memory that are not in the EPROM? Try printing out the parameters to the EEPROM_Read2ByteSigned function.[/quote]
Aah...good point. I'll check that exhaustively today. They appear to read/write and retain their value fine, though, suggesting that they are indeed EEPROM.

Quote:
Maybe the serial buffers are overflowing, are you checking the return values of printf?
I didn't even know printf returned anything...
What is the expected return value? I would assume 0, and nonzero is failure...but I never thought about it at all.

Thanks so much for continuing to check this thread. I've had another printf bug thread die quickly with not many replies...

JBot
__________________
Aren't signatures a bit outdated?
  #9   Spotlight this post!  
Unread 10-02-2008, 20:02
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Printf prints only the first character

" On success the number of input fields converted and stored are returned. If an input failure occurred, then EOF is returned."


HTH
  #10   Spotlight this post!  
Unread 10-02-2008, 21:57
bear24rw's Avatar
bear24rw bear24rw is offline
Team 11 Programming Captain
AKA: Max T
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2005
Location: Flanders, NJ
Posts: 385
bear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to behold
Send a message via AIM to bear24rw
Re: Printf prints only the first character

try not calling frunctions from the printf i have had trouble with that in the past..
  #11   Spotlight this post!  
Unread 12-02-2008, 15:12
Mike Mahar Mike Mahar is offline
Registered User
FRC #0138
 
Join Date: Jan 2007
Location: Amherst, NH
Posts: 64
Mike Mahar will become famous soon enough
Re: Printf prints only the first character

I just started having this same problem last night as well. It seems to be a series of printfs that are in a single if block. I can comment out any combination of them and get the same result. The one thing I didn't check was passing a byte as an argument although Ithink I've done this in the past without problems.

Subsequent printfs don't seem to be a problem. One symptom is that I have multiple lines in single printfs (ie. printf("x=%d\n\ry=%d\n\r", x, y) I get the first character of each line not just the first character of the printf.
  #12   Spotlight this post!  
Unread 12-02-2008, 17:24
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Printf prints only the first character

This is smelling like a stack issue.

HTH
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
THE FIRST AND ONLY PALMETTO FANTASY FIRST LEAGUE (so far!) Billfred Fantasy FIRST 106 04-04-2005 22:52
printf isn't printf-ing. Help! Meandmyself Programming 14 15-02-2004 16:27
pic: And it's only the first day... CD47-Bot Chit-Chat 8 17-01-2004 20:21
An effort to get all the blue prints measurment archiver 2001 1 23-06-2002 22:43


All times are GMT -5. The time now is 19:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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