Jump to content
kevinst

One Wire Library Issues

Recommended Posts

Hello,

 

I have an issue with the timing of the SourceBoostC One Wire library. With a 16F877 running at 8 Mhz and a DS1820 temp sensor, the oo libs constantly return -1 with #Pragma CLOCK_FREQ 8000000, however, If I change the #Pragma CLOCK_FREQ to 6000000 I get valid data. But then all the other timing loops are incorrect...

 

I have the Starndard version so lib source is not available. Is this a bug or am I doing something wrong? I"m fairly new to SourceBoost...

 

Attached is the source code which was obtained mainly from the SourceBoost Documentation. I'm using SourceBoostC 6.85

 

Any advise is appreciated...

 

Thanks,

 

Kevin

 

#include <system.h>

//Target PIC16F877 configuration word
#pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF

//Set clock frequency
#pragma CLOCK_FREQ	6000000 //8000000 will fail to read valid oo data

#define LCD_ARGS 	1,	/* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
	0, 		/* Use busy signal: 1 = use busy, 0 = use time delays */\
	PORTB, TRISB, 	/* Data port and data port tris register */ \
	PORTB, TRISB, 	/* Control port and control port tris register */ \
	4,		/* Bit number of control port is connected to RS */ \
	6,		/* Bit number of control port is connected to RW */ \
	5 		/* Bit number of control port is connected to Enable */

#include <lcd_driver.h> // include the LCD template code

#define OO_PORT PORTA
#define OO_TRIS TRISA
#define OO_PIN  0

volatile bit oo_bus@OO_PORT.OO_PIN;
volatile bit oo_bus_tris@OO_TRIS.OO_PIN;

#include <oo.h>

void main( void )
{
//Configure port A
trisa = 0x01;
//Configure port B
trisb = 0x00;
//Configure port C
trisc = 0x00;

//Configure A/D pins
adcon1 = 0x07;

lcd_setup();
lcd_clear();

lprintf( "Air Temp:" );

//Endless loop
while( 1 )
{
	// Reset the one wire bus
	oo_busreset();
	porta.1 = 1;

	// Start the temparature conversion (non-blocking function)
				oo_start_conversion();

	oo_wait_for_completion();

	// Read the scratchpad
	oo_read_scratchpad();

	// And extract the temperature information
				short temp = oo_get_data();
	bool remain = temp & 0x01;

	lcd_gotoxy( 9, 0 );
							lprintf( "%3d", temp >> 0x01 );
							if (remain)  {
		lprintf(".5");	 }
							else  {
		lprintf(".0");	 }

							lcd_gotoxy( 14,0);
							lprintf( " C");		

	delay_s(1);		
}

}

Edited by kevinst
wrapped code into code tags for better readability

Share this post


Link to post
Share on other sites
Hello,

 

I have an issue with the timing of the SourceBoostC One Wire library. With a 16F877 running at 8 Mhz and a DS1820 temp sensor, the oo libs constantly return -1 with #Pragma CLOCK_FREQ 8000000, however, If I change the #Pragma CLOCK_FREQ to 6000000 I get valid data. But then all the other timing loops are incorrect...

 

I have the Starndard version so lib source is not available. Is this a bug or am I doing something wrong? I"m fairly new to SourceBoost...

 

Attached is the source code which was obtained mainly from the SourceBoost Documentation. I'm using SourceBoostC 6.85

 

Any advise is appreciated...

 

Thanks,

 

Kevin

 

#include <system.h>

//Target PIC16F877 configuration word
#pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF

//Set clock frequency
#pragma CLOCK_FREQ	6000000 //8000000 will fail to read valid oo data

#define LCD_ARGS 	1,	/* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
	0, 		/* Use busy signal: 1 = use busy, 0 = use time delays */\
	PORTB, TRISB, 	/* Data port and data port tris register */ \
	PORTB, TRISB, 	/* Control port and control port tris register */ \
	4,		/* Bit number of control port is connected to RS */ \
	6,		/* Bit number of control port is connected to RW */ \
	5 		/* Bit number of control port is connected to Enable */

#include <lcd_driver.h> // include the LCD template code

#define OO_PORT PORTA
#define OO_TRIS TRISA
#define OO_PIN  0

volatile bit oo_bus@OO_PORT.OO_PIN;
volatile bit oo_bus_tris@OO_TRIS.OO_PIN;

#include <oo.h>

void main( void )
{
//Configure port A
trisa = 0x01;
//Configure port B
trisb = 0x00;
//Configure port C
trisc = 0x00;

//Configure A/D pins
adcon1 = 0x07;

lcd_setup();
lcd_clear();

lprintf( "Air Temp:" );

//Endless loop
while( 1 )
{
	// Reset the one wire bus
	oo_busreset();
	porta.1 = 1;

	// Start the temparature conversion (non-blocking function)
				oo_start_conversion();

	oo_wait_for_completion();

	// Read the scratchpad
	oo_read_scratchpad();

	// And extract the temperature information
				short temp = oo_get_data();
	bool remain = temp & 0x01;

	lcd_gotoxy( 9, 0 );
							lprintf( "%3d", temp >> 0x01 );
							if (remain)  {
		lprintf(".5");	 }
							else  {
		lprintf(".0");	 }

							lcd_gotoxy( 14,0);
							lprintf( " C");		

	delay_s(1);		
}

}

 

Hello,

The libary code for one wire library use the nop() instruction. They should rewrite this lib becasue now it´s not working with different clock frequency. A work around is to run goodies if you have pro licens and change the code your self. Or you can download the lib code from lika.be

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...