[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] printf_P question

From: wbounce
Subject: [avr-gcc-list] printf_P question
Date: Fri, 3 Jun 2005 00:39:29 -0400

I am getting missing data on 2 printf that I can not figure out.

//Variable definitions
volatile double gnLatDegree, gnLongDegree;
volatile uint8_t gnValidData;
volatile double gntrackgood;
volatile double gngroundspeedknots;
volatile int16_t TargetBearing,SlowBearing, CurrentBearing;
const char gcOutputStatus[] PROGMEM = "Long %10.6f Lat %9.6f H %6.2f Kn
%6.2f CB %5.1f TB %5.1f V %c\r\n";

printf_P(gcOutputStatus,gnLongDegree, gnLatDegree, gntrackgood,
gngroundspeedknots, CurrentBearing, TargetBearing,(char) gnValidData);
.. Output 
Long  75.217300 Lat 40.166611 H 263.10 Kn   0.70 CB   0.0 TB  48.5 V  
CB is 0.0 even if I set CurrentBearing = TargetBearing 
And V is either empty or some weird character when it should be either V
or A.

// var declares
volatile uint32_t DistanceFeet,LeftDistance,
LastLeftDistance,RightDistance, LastRightDistance;

In interupt routine for left encoder

In interupt routine for right encoder

//In a function
double Distance;
uint32_t CurrentLeft,CurrentRight; 
        CurrentLeft =  LeftDistance  - LastLeftDistance  ;
        CurrentRight = RightDistance  - LastRightDistance ;
        LastLeftDistance = LeftDistance ;
        LastRightDistance = RightDistance ;
        SREG=Sreg ; // restored interrupts

printf_P(PSTR("CL %i LD %i CR %i RD %i D %f

CL 224 LD 0 CR 2017 RD 0 D 0.000000 

CL and CR show up but LD and RD are 0 which should not be true because
the next output show new higher CL and CR so LeftDistance has to be
increasing and get assigned to LastLeftDistance. So why does
LastLeftDistance show as 0?

Is there some problem with printf and global volatile  variables? I
purposely choose LastLeftDistance  because it was not being increments
outside of the readspeed routine. It does not seem to have a problem
with the local variables. 

Or is there something else wrong here?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]