View previous topic :: View next topic |
Author |
Message |
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
Ds18b20 by 18f4520 |
Posted: Tue Dec 28, 2010 4:47 am |
|
|
Dear member again I'm in problem with 18f4520
My program works well in Proteus but not in real board.
I use common ds18b20 program and modified
Code: |
/*-------1-wire definitions-------*/
#define ONE_WIRE_PIN PIN_D0
/*******************1-wire communication functions********************/
|
that portion
and use flex driver for lcd.
But my program always show TEMP=0'C.
Heres my code for fuses:
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES PUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode enabled
#FUSES NOFCMEN //Fail-safe clock monitor enabled
#FUSES NOPBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOLPT1OSC //Timer1 configured for low-power operation
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode enabled
#use delay (INTERNAL=8MHZ)
|
then my original program
Code: |
void main()
{
Delay_ms(500);
lcd_init();
onewire_write(0xCC);
onewire_write(0x4E);
onewire_write(125);
onewire_write(-55); //this should be done for proper working of DS18B20
onewire_write(127);
onewire_reset();
onewire_write(0xCC);
onewire_write(0x48);
delay_ms(15);
TEMP=ds1820_read();
while(1)
{
TEMP=ds1820_read();
lcd_gotoXY(1,1);
printf(lcd_putc, "Temp=%u",TEMP);
lcd_putc(223);
lcd_putc("C ");
}
}
|
regards
misel |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 28, 2010 3:15 pm |
|
|
You are using code for multiple ds18b20 sensors.
Try the code at the start of the thread below. It's for one sensor.
http://www.ccsinfo.com/forum/viewtopic.php?t=28425
Be sure to comment the first line and un-comment the 2nd line in the
calculation code, so it looks like this:
Code: |
//result = (float) temp3 / 2.0; //Calculation for DS18S20 with 0.5 deg C resolution
result = (float) temp3 / 16.0; //Calculation for DS18B20 with 0.1 deg C resolution |
|
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
reply |
Posted: Thu Dec 30, 2010 5:02 am |
|
|
Yes sir I implemented that code you gave me.
But still having problem with 18f4550.
Now I change my ic and take 18f452 and use internal crystal and get 99.99% accurate. means temperature does not become 0.
I get output real.
Is that problem with my 18f4550 or ? I don't know.
Now I solve my problem by changing IC. Is not a good solution.
thanks
Misel |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Thu Dec 30, 2010 10:49 am |
|
|
There is no such thing as an 'internal crystal', on _any_ PIC. You are using an internal RC oscillator. If this works, and code using the external crystal does not, then it says you have a problem with your external circuitry, or the settings you are using....
Now some odd comments. You refer to a 18f4550, but the only code posted was for a 18f4520. Which are you using?.
The posted code is using the internal RC circuit.
Proteus, is notorious for allowing 'wrong' oscillator fuse settings to work.
So, post:
What chip?.
What oscillator?.
What fuses and clock settings?.
How is the external circuitry actually built (PCB, breadboard, etc. etc.)?.
What compiler version?.
Best Wishes |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
reply for Ttelmah |
Posted: Sat Jan 01, 2011 2:09 am |
|
|
Dear sir thanks for the reply.
Yes firstly I tried in 18f4550.
But now for getting problem there I shift in 18f4520.
Now I'm using 18f4520 and oscillator is internal RC oscillator 8MHz.
Fuse setting was in my previous post.
External is in PCB.
Compiler verson PCW4.049.
Fuse setting I used in 18f4550 is given below:
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOLPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
//#FUSES PLL1 //Divide By 5(20MHz oscillator input)
//#FUSES CPUDIV1 //No System Clock Postscaler
#FUSES NOUSBDIV //USB clock source comes from primary oscillator
#FUSES NOVREGEN //USB voltage regulator enabled
#FUSES NOICPRT //ICPRT disabled
#use delay(clock=8000000)
|
I use burner Smartpro X5.
Fuse setting of Smartpro is
FOSC3-FOSC0=1100
PWRT=1,DEBUG=1
Thats all.
Again thanks for reply.
Regards misel |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
Ttelmah |
Posted: Sat Jan 01, 2011 6:00 am |
|
|
Dear sir,
I'm still having problem.
Another thing I'm accessing two Dallas from two pins. I did it the easiest way just make two function and accessed it by calling
Code: |
#include <ds18b20_1.c>
#include <ds18b20_2.c>
|
and use name of different pin
Code: |
define ONE_WIRE_PIN PIN_A0
define ONE_WIRE_PIN2 PIN_A0
|
and change every func name in two file such as
Code: |
onewire_reset() in _1 file
onewire_reset2() in _2 file
|
Both dallas shows garbage result means 1,2,20,15,30 etc in different time execution.
thanks
Misel |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
still having problem |
Posted: Sat Jan 01, 2011 6:01 am |
|
|
still having problem with 18f4550
but not in 18f4520
thanks
regards Misel |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Jan 01, 2011 8:42 pm |
|
|
Quote: | Compiler verson PCW4.049 | There used to be a sticky topic at the top of this discussion forum where the problems in the new V4 compiler version were discussed but since the comiler has been stable now for over a year the sticky tag has been removed and the topic moved many pages down.
In short, your compiler is a very old and unreliable version that shouldn't be used. In releasing the new v4 compiler CCS has made many releases of the new product using the users as a Test Team. Only around version number 4.070 the compiler became stable enough to compile the programs again that were working properly in the old v3.249
You are lucky with your compiler version to have some things working, but it is a waste of your (and our) time to continue using it. Please upgrade to a recent version or downgrade to the stable v3.249 that was available at your time pf purchase. |
|
|
|