|
|
View previous topic :: View next topic |
Author |
Message |
Bozidar Benc Guest
|
[newbie quiestion] Reading from DS1620 |
Posted: Mon Feb 24, 2003 1:14 pm |
|
|
Hi,
I'm going to start writing my first PIC program. It will run on the 16F877 micro and must (among other things) read the temperature from the DS1620 sensor.
CCS compiler comes with the support for the DS1621 sensor, but, as I know from reading data sheets, it is not compatible with DS1620.
Can anyone offer some help?
TiA
Bozidar
___________________________
This message was ported from CCS's old forum
Original Post ID: 12065 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: [newbie quiestion] Reading from DS1620 |
Posted: Mon Feb 24, 2003 1:27 pm |
|
|
:=Hi,
:=
:=I'm going to start writing my first PIC program. It will run on the 16F877 micro and must (among other things) read the temperature from the DS1620 sensor.
:=
:=CCS compiler comes with the support for the DS1621 sensor, but, as I know from reading data sheets, it is not compatible with DS1620.
---------------------------------------------------------
The DS1620 uses SPI, so you could look at the CCS driver file
DS1302.C, which is in this folder:
c:\Program Files\Picc\Drivers
Also, Peter Anderson has an SPI example:
<a href="http://www.phanderson.com/PIC/PICC/CCS_PCM/ds1602_1.html" TARGET="_blank">http://www.phanderson.com/PIC/PICC/CCS_PCM/ds1602_1.html</a>
You'll still have to read the data sheet closely, and adapt
this source code to your chip.
DS1302 data sheet:
<a href="http://pdfserv.maxim-ic.com/arpdf/DS1302.pdf" TARGET="_blank">http://pdfserv.maxim-ic.com/arpdf/DS1302.pdf</a>
DS1602 data sheet:
<a href="http://pdfserv.maxim-ic.com/arpdf/DS1602.pdf" TARGET="_blank">http://pdfserv.maxim-ic.com/arpdf/DS1602.pdf</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12066 |
|
|
Sherpa Doug Guest
|
Re: [newbie quiestion] Reading from DS1620 |
Posted: Mon Feb 24, 2003 1:29 pm |
|
|
:=Hi,
:=
:=I'm going to start writing my first PIC program. It will run on the 16F877 micro and must (among other things) read the temperature from the DS1620 sensor.
:=
:=CCS compiler comes with the support for the DS1621 sensor, but, as I know from reading data sheets, it is not compatible with DS1620.
:=
:=Can anyone offer some help?
:=
:=TiA
:=
:=Bozidar
If you are going to be writing embedded uP code you better get used to writing your own drivers. Look at the data sheets for the DS1620 and DS1621 and see what the differences are. Then look at the code CCS gives you for the DS1621 and modify it for the DS1620.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12067 |
|
|
Bozidar Benc Guest
|
Re: [newbie quiestion] Reading from DS1620 |
Posted: Mon Feb 24, 2003 1:46 pm |
|
|
Wow! That was fast!!!
Thanks a lot for the answer. It's enough to get me started.
Best regards
Bozidar
:=---------------------------------------------------------
:=The DS1620 uses SPI, so you could look at the CCS driver file
:=DS1302.C, which is in this folder:
:=c:\Program Files\Picc\Drivers
:=
:=Also, Peter Anderson has an SPI example:
:= <a href="http://www.phanderson.com/PIC/PICC/CCS_PCM/ds1602_1.html" TARGET="_blank"> <a href="http://www.phanderson.com/PIC/PICC/CCS_PCM/ds1602_1.html" TARGET="_blank">http://www.phanderson.com/PIC/PICC/CCS_PCM/ds1602_1.html</a></a>
:=
:=You'll still have to read the data sheet closely, and adapt
:=this source code to your chip.
:=
:=DS1302 data sheet:
:= <a href="http://pdfserv.maxim-ic.com/arpdf/DS1302.pdf" TARGET="_blank"> <a href="http://pdfserv.maxim-ic.com/arpdf/DS1302.pdf" TARGET="_blank">http://pdfserv.maxim-ic.com/arpdf/DS1302.pdf</a></a>
:=
:=DS1602 data sheet:
:= <a href="http://pdfserv.maxim-ic.com/arpdf/DS1602.pdf" TARGET="_blank"> <a href="http://pdfserv.maxim-ic.com/arpdf/DS1602.pdf" TARGET="_blank">http://pdfserv.maxim-ic.com/arpdf/DS1602.pdf</a></a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12069 |
|
|
mark r. hahn Guest
|
Re: [newbie quiestion] Reading from DS1620 |
Posted: Tue Feb 25, 2003 12:21 pm |
|
|
Bozidar,
I wrote a couple of routines to do this a few weeks ago. You're welcome to try them out. You will need to define DQ_PIN, CLK_PIN, and RST_PIN.
Have fun,
Mark R Hahn
*** CODE FOLLOWS ***
// DS1620 sensor code
#ifdef SENSOR_DS1620
#define CLK_PIN PIN_A3
#define DQ_PIN PIN_A1
#define RST_PIN PIN_A2
//
// write_ds1620
// Write a byte to the DS1620
//
void write_ds1620(byte cmd)
{
byte i;
for(i=0; i<8; i++)
{
output_low(CLK_PIN);
output_bit(DQ_PIN, shift_right(&cmd,1,0));
output_high(CLK_PIN);
}
}
//
// init_temp
// Initialize the DS1620
//
void init_temp()
{
// set CLK and RST to correct state
output_high(CLK_PIN);
delay_us(2);
output_low(RST_PIN);
// set config to continuous conversion
// and CPU communications mode
output_high(RST_PIN);
write_ds1620(0x0C);
write_ds1620(0x02);
output_low(RST_PIN);
// start conversion
output_high(RST_PIN);
write_ds1620(0xEE);
output_low(RST_PIN);
}
//
// read_temp
// Read the temperature from the DS1620.
// Temperature readings are signed 9 bits and range from -55 C to 125 C
// in .5 degree C increments. A reading of zero represents 0 degrees C.
//
// Result returned in temp_data.
//
signed long int temp_data;
void read_temp()
{
byte i;
output_high(RST_PIN);
write_ds1620(0xAA);
// make DQ an input
set_tris_a(0xE2);
temp_data = 0L;
for(i=0; i<9; i++)
{
output_low(CLK_PIN);
temp_data = temp_data >> 1;
if (input(DQ_PIN))
{
temp_data = temp_data | 0x100;
}
output_high(CLK_PIN);
}
// make DQ an output
set_tris_a(0xE0);
output_low(RST_PIN);
}
#endif
:=Hi,
:=
:=I'm going to start writing my first PIC program. It will run on the 16F877 micro and must (among other things) read the temperature from the DS1620 sensor.
:=
:=CCS compiler comes with the support for the DS1621 sensor, but, as I know from reading data sheets, it is not compatible with DS1620.
:=
:=Can anyone offer some help?
:=
:=TiA
:=
:=Bozidar
___________________________
This message was ported from CCS's old forum
Original Post ID: 12087 |
|
|
Bozidar Benc Guest
|
Re: [newbie quiestion] Reading from DS1620 |
Posted: Tue Feb 25, 2003 1:01 pm |
|
|
:=Bozidar,
:=
:=I wrote a couple of routines to do this a few weeks ago. You're welcome to try them out. You will need to define DQ_PIN, CLK_PIN, and RST_PIN.
:=
:=Have fun,
:=
:=Mark R Hahn
Thanks a lot! This forum is really great!
Bozidar
___________________________
This message was ported from CCS's old forum
Original Post ID: 12089 |
|
|
balu Guest
|
ds1620 code |
Posted: Fri Mar 11, 2005 9:35 am |
|
|
hai iam having few doubts i underlined them
if any one know how to solve the following please let me know, iam really in my dead line,
*** CODE FOLLOWS ***
// DS1620 sensor code
#ifdef SENSOR_DS1620 #define CLK_PIN PIN_A3
#define DQ_PIN PIN_A1
#define RST_PIN PIN_A2
//
// write_ds1620
// Write a byte to the DS1620
//
void write_ds1620(byte cmd)
{
byte i;
for(i=0; i<8; i++)
{
output_low(CLK_PIN);
output_bit(DQ_PIN, shift_right(&cmd,1,0));
output_high(CLK_PIN);
}
}
//
// init_temp
// Initialize the DS1620
//
void init_temp()
{
// set CLK and RST to correct state
output_high(CLK_PIN);
delay_us(2);
output_low(RST_PIN);
// set config to continuous conversion
// and CPU communications mode
output_high(RST_PIN);
write_ds1620(0x0C);
write_ds1620(0x02);
output_low(RST_PIN);
// start conversion
output_high(RST_PIN);
write_ds1620(0xEE);
output_low(RST_PIN);
}
i have seen this code in this forum,,
iam using picc compiler, and it doesnt have the ds1620.h header file,, is it necessary to have ds1620.h header file to run those commands i underlined..
how to tell to ds1620 that 0c is config register,,
it would be very great ful if anyone help me out, thanks a lot
cheers
balu |
|
|
TaiChipY
Joined: 11 Mar 2005 Posts: 21
|
|
Posted: Fri Mar 11, 2005 11:03 am |
|
|
Bog Bozidar !
If you need something else ( explanations ) regarding temperature projects, let my know. I have one small project in this part and it should
fit your needs...
C ya
Javi ako kaj trebas...
TaiChipY |
|
|
balu Guest
|
how to initialize ds1620 |
Posted: Sun Mar 13, 2005 4:47 am |
|
|
hai ya, thanx a lot, i really need some explanations reagarding temperature reading and writing with ds1620, if your project help me this out, that would be great ful, already i wasted a lot of time on it,, plzz help me out if any one know this
and my problem is in the previous thread code ,
output_high(RST_PIN);
write_ds1620(0x0C);
write_ds1620(0x02);
output_low(RST_PIN);
i think there is no write_ds1620 command in the ccs compiler,, probably i think ineed ds1620 header file so that this command might work , oc command is for the write config in ds1620,, so if i have to tell ds1620 can i use like this--initially after rst pin enable i have to send a simulataneous clock signal with oc[i.e 00001100],,then again i have to send to select bits for the status register, i.e conversion mode/stand alone mode/cpu.... is this method is right?? huh totally in confusion
thanx a lot.. cheers
TaiChipY wrote: | Bog Bozidar !
If you need something else ( explanations ) regarding temperature projects, let my know. I have one small project in this part and it should
fit your needs...
C ya
Javi ako kaj trebas...
TaiChipY |
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: how to initialize ds1620 |
Posted: Sun Mar 13, 2005 8:22 am |
|
|
balu wrote: | i think there is no write_ds1620 command in the ccs compiler,, probably i think ineed ds1620 header file so that this command might work |
I am guessing that this must be a student project and that you are not familar with programming? This reason I say this is because you supplied that "function"
Code: |
//
// write_ds1620
// Write a byte to the DS1620
//
void write_ds1620(byte cmd)
{
byte i;
for(i=0; i<8; i++)
{
output_low(CLK_PIN);
output_bit(DQ_PIN, shift_right(&cmd,1,0));
output_high(CLK_PIN);
}
}
|
|
|
|
balu
Joined: 13 Mar 2005 Posts: 5
|
Re: how to initialize ds1620 |
Posted: Mon Mar 14, 2005 9:54 am |
|
|
yes, ur right, iam not experienced with this programming , iam in starting stage,,
i ll tell u clearly where iam strucking,, .. 0c is the command for write a config regfister in ds1620, so it needs 8 clock cycles to take 00001100(i.e 0c) ,after this again i have to set rst pin and send 8 more bits to select which is continous/ cpu/ so..on,
but write_ds1620 is not recognising by the compiler,, so ineed to send 8 clock cycles for the write config register(i.e 0c) and again 8 clock cycles along with 8 bit data to cpu mode/ conversion mode so..on,,,, is it right way ?? or does the write_ds1620 will take the point directly to 0c register in ds1620 with out any clock cycles given from the software.
sorry for my weak questions.
thanx a lot
cheers
I am guessing that this must be a student project and that you are not familar with programming? This reason I say this is because you supplied that "function"
Code: |
//
// write_ds1620
// Write a byte to the DS1620
//
void write_ds1620(byte cmd)
{
byte i;
for(i=0; i<8; i++)
{
output_low(CLK_PIN);
output_bit(DQ_PIN, shift_right(&cmd,1,0));
output_high(CLK_PIN);
}
}
| [/quote] |
|
|
balu
Joined: 13 Mar 2005 Posts: 5
|
please check this code |
Posted: Thu Mar 17, 2005 3:18 pm |
|
|
hai evryone, itz me again, i have written some code to activate ds1620, still it is not working. actually this code doesnt show the temperature readings, but it will just check weather some signal is comming from ds1620. so if any one can spare for 5 mins please have a look and suggest me where the problem is and why iam not able to get the ouput.
/*ds1260.c iam using pic 16f876 which has two 7 segment led displays*/
#include <16F876.h>
#device 16F876 ICD=TRUE
#use delay(clock=4000000)
#fuses XT,NOWDT, NOPROTECT, NOPUT, NOBROWNOUT
#define led_delay 500
#define digitbit 49 /* for left display LB0 = (8x6)+1 */
#define digitbit1 48 /* for right display RB0 = (8x6)+0 */
#define clk_c0 56 /* portc 0 bit */
#define rst_c1 57 /* portc 1 bit */
#define ip_c5 61 /* portc 5 bit the i/p of ds1620 is been connected to 5th pin of pic*/
#define input 0xff
#define output 0x00
#define port_c 0x07
/*#define temp 0x22, i havent defined temp variable it automatically taking 22h for temp, so the below tempmsb has been caluculated like 22* 8+7=183*/
#define tempmsb 183
#define config 0x0c
#define valbit 176 /* here the 22 byte 0th bit same as above*/
#define seg7zero 0x3f
#define seg7one 0x06
#define rstdelay 5
/* write function*/
void write_ds1620(byte adrs)
{
byte i;
int value;
for(i=0; i<8; i++)
{
output_low(clk_c0);
adrs =adrs>>1;
value=adrs&0x01;
if(value==0x01)
{
output_high(ip_c5);
}
else
output_low(ip_c5);
output_high(clk_c0);
delay_us(1);
}
delay_us(rstdelay);
}
void main()
{
while(1)
{
byte rawtemp,temp=0x02;
int i;
int cnt = 0;
set_tris_c(0xdc); /*11011100*/
delay_us(rstdelay);
output_high(rst_c1);
write_ds1620(config);
write_ds1620(0x02);
write_ds1620(0xee);
write_ds1620(0xaa);
output_low(rst_c1);
set_tris_c(0x20); /* reading from ds 1620*/
output_high(rst_c1);
for(i=0; i<8; i++)
{
output_low(clk_c0);
temp=temp/2; /*22h*/
if(bit_test(*port_c,0x05))
output_high(tempmsb);
else
output_low(tempmsb);
output_high(clk_c0);
delay_us(1);
}
output_low(rst_c1);
delay_us(rstdelay);
/*stop conversion*/
set_tris_c(0xdc);
write_ds1620(0x22);
/*display*/
/*following checks the lsb of temp register where the reading has taken from the ds1620 . if any data is comming it will get some value in the register so it checks the lsb of the temp(22h) register and displays according to lsb.*/
set_tris_c(0x00);
if(bit_test(*temp,0x00))
{
output_high(digitbit1);
output_c(seg7one);
delay_us(led_delay);
}
else
{
output_high(digitbit);
output_c(seg7zero);
delay_us(led_delay);
}
}/*while*/
}/*main*/ |
|
|
balu
Joined: 13 Mar 2005 Posts: 5
|
|
Posted: Fri Apr 01, 2005 8:11 am |
|
|
hai , mark
i just need to clarify something,,
when ur taking readings from ds1620,, the hexadecimal value ur getting is the output or u need to divide the value with 2 ,, to get the actual temperature,,
for example iam gettin 17h,, so is the temperature is 23 degrees centigrade,, or i need to divide 17h/2 to i.e 12 degrees(approx)..
could you please clarify this doubt for me, thanx a lot,, |
|
|
balu
Joined: 13 Mar 2005 Posts: 5
|
ds1620 output |
Posted: Fri Apr 01, 2005 8:13 am |
|
|
hai , mark
i just need to clarify something,,
when ur taking readings from ds1620,, the hexadecimal value ur getting is the output or u need to divide the value with 2 ,, to get the actual temperature,,
for example iam gettin 17h,, so is the temperature is 23 degrees centigrade,, or i need to divide 17h/2 to i.e 12 degrees(approx)..
could you please clarify this doubt for me, thanx a lot,, |
|
|
|
|
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
|