CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with output_float ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
freesat



Joined: 08 Feb 2011
Posts: 32

View user's profile Send private message

Problem with output_float ?
PostPosted: Mon May 12, 2014 10:32 pm     Reply with quote

Hi, i have problem passing PIN as function parameter and output_float, see sample codes below.

Code:

// this one works fine, with fixed const PIN
using: x = onewire_read();

int onewire_read() {
   int count, data;

   for (count=0; count<8; ++count) {
      output_low( PIN_B0 );
      delay_us( 2 );
      output_float( PIN_B0 );
      delay_us( 8 );
      shift_right(&data,1,input( PIN_B0 ));
      delay_us( 120 );
   }

   return( data );
}


Code:

// This works!!! ouput_float is not accepting PIN_B0 passed on parameter
using: x = onewire_read( PIN_B0 );

int onewire_read( int16 one_wire_pin ) {
   int count, data;

   for (count=0; count<8; ++count) {
      output_low( one_wire_pin );
      delay_us( 2 );
      output_float( PIN_B0 );  // SEE THIS LINE
      delay_us( 8 );
      shift_right(&data,1,input( one_wire_pin ));
      delay_us( 120 );
   }

   return( data );
}


Code:

// This wont works!
using: x = onewire_read( PIN_B0 );

int onewire_read( int16 one_wire_pin ) {
   int count, data;

   for (count=0; count<8; ++count) {
      output_low( one_wire_pin );
      delay_us( 2 );
      output_float( one_wire_pin );
      delay_us( 8 );
      shift_right(&data,1,input( one_wire_pin ));
      delay_us( 120 );
   }

   return( data );
}


so there is a problem with output_float? or im doing something wrong?

PS. Tested with version 5.025 and real hardware ( DS18B20 )
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Mon May 12, 2014 10:47 pm     Reply with quote

I believe you'll need to use a pointer to solve this.
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 13, 2014 6:54 am     Reply with quote

also.... from the help files..
"Note that doing I/0 with a variable instead of a constant will take much longer time."

so I wonder if that's your problem...a timing issue or does it just 'fail'.

depending on application, it might be easier,quicker, smaller code to create 'fixed' code functions instead of variables?

also... as this code accesses an RTC why the 'variable' pin requirement ? There's a working driver in the code library. Normally you only have one RTC per PIC.

curious

jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue May 13, 2014 8:28 am     Reply with quote

what does the .LST file show after you compile for that region of code ??

does the pin number ( from the device.H file) show up as expected ?
freesat



Joined: 08 Feb 2011
Posts: 32

View user's profile Send private message

PostPosted: Tue May 13, 2014 3:30 pm     Reply with quote

Quote:

hi stinkyi, thanks for reply, i try pass parameter as pointer, does not help!


Quote:

Hi Temtronic, thanks for reply, is not just time delay issue, it fail completly, u can wait forever, and it never does expedtec.

I need variable code to read 4 ( 1wire lines on same pic ), so create same code four times to do the same, sound no good.

( it is for DS18B20 temperature sensors, read a lot of sensors, so need more than one pin with more than one sensor on each pin, not RTC, i prefer ds3231/i2c as RTC. )

something like this....
read_onewire( PIN_B0, SensorID1 )
.....
read_onewire( PIN_B0, SensorID5 )

read_onewire( PIN_B1, SensorID1 )
.....
read_onewire( PIN_B1, SensorID5 )

read_onewire( PIN_B2, SensorID1 )
.....
read_onewire( PIN_B2, SensorID5 )


Quote:

Hi asmboy, thanks for reply, see below for .lst produced by compiler



Code:

....................       output_float( PIN_B0 ); // Using const
045D:  BSF    03.5
045E:  BSF    06.0



Code:

....................       output_float( one_wire_pin ); // Using variable parameter
045D:  MOVF   44,W
045E:  MOVWF  48
045F:  MOVLW  01
0460:  MOVWF  49
0461:  CLRF   4B
0462:  MOVLW  80
0463:  MOVWF  4A
0464:  CALL   397

[/quote]
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue May 13, 2014 3:47 pm     Reply with quote

ok the problem is clear to me .

RTM !! Very Happy Very Happy Very Happy

quoting what is expected by the compiler - of the argument supplied to
output_float(PIN);

Quote:

Requires: Pin constants are defined in the devices .h file


the compiler SHOULD have error-ed when you spec'd a VAR instead of a constant, but instead went spinning off the rails as .LST shows.
IS there any more to be learned from the CALL at 397 ?? - as you did not show what was there .

SO....
as-is the function expects a CONSTANT, which it encodes at compile time-
and in runtime - as per the Urban dictionary -you are SOOL

there is of course a way to deal with what you want to do - but not using a VAR.


Last edited by asmboy on Tue May 13, 2014 5:13 pm; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 13, 2014 5:04 pm     Reply with quote

oops...been a long week, already burned out...OK...not RTC but temp sensor...

If they all have IDs, you can run an 'interrogation' function, get their ids, then use that 'database' to access them as required.

In my case( 2 sensors, solar wall project), using a second I/O pin was easier to code,simpler to wire and a bit more reliable. The ones I used were the PS type( parasitic mode) so 2 wires per sensor( I/O pin and ground).
I also tend to use 40 pin PICs for every project.I know 'overkill' but seem to always need 'just one more pin....'

Just another way to use them.....

hth
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 13, 2014 6:15 pm     Reply with quote

This is in the forum archives. See my post about 1/2 way down this
thread which explains the timing issues:
http://www.ccsinfo.com/forum/viewtopic.php?t=36953
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group