It is currently 23 Apr 2019 21:01

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 15 Jan 2019 14:23 
Offline

Joined: 25 Jun 2017 18:06
Posts: 24
Hello

I use the included example to read a DS18B20.
There is the possibility to change the resolution.
A look at the data sheet says i must Change the bits R0 and R1 .
Just how do I tell my program.
I do not want to succeed in this.
Can anyone help me with that? :?

/*
 * Project name:
     OneWire (Interfacing the DS1820 temperature sensor - all versions)
 * Copyright:
     (c) Mikroelektronika, 2012.
 * Revision History:
       - initial release;
 * Description:
     This code demonstrates one-wire communication with temperature sensor
     DS18x20 connected to PA3 pin.
     MCU reads temperature from the sensor and prints it on the TFT.
     The display format of the temperature is 'xxx.xxxx°C'. To obtain correct
     results, the 18x20's temperature resolution has to be adjusted (constant
     TEMP_RESOLUTION).
* Test configuration:
     Device:          STM32F107VC
                      http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00220364.pdf
     Dev.Board:       EasyMx v7 for STM(R) ARM(R)
                      http://www.mikroe.com/easymx-pro/stm32/
                      ac:temperature_sensor                     
     Oscillator:      HSE-PLL, 72.000MHz
     Ext. Modules:    EasyTFT
                      http://www.mikroe.com/add-on-boards/display/easytft/
                      ac:EasyTFT                     
     SW:              mikroC PRO for ARM
                      http://www.mikroe.com/mikroc/arm/
 * NOTES:
     - Place DS1820 sensor on board. Turn DS1820 switch at SW14.6. Turn on TFT backlight at SW11 switch.
 */

// TFT module connections
unsigned int TFT_DataPort at GPIOE_ODR;
sbit TFT_RST at GPIOE_ODR.B8;
sbit TFT_RS at GPIOE_ODR.B12;
sbit TFT_CS at GPIOE_ODR.B15;
sbit TFT_RD at GPIOE_ODR.B10;
sbit TFT_WR at GPIOE_ODR.B11;
sbit TFT_BLED at GPIOE_ODR.B9;
// End TFT module connections

//  Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
//  18S20: 9  (default setting; can be 9,10,11,or 12)
//  18B20: 12
#include "Resources.h"
const unsigned short TEMP_RESOLUTION = 12;

char *text = "000,0000  C";
unsigned temp;
 int intme;

void DrawScr() {
  TFT_Init_ILI9341_8bit(320, 240);
  TFT_Fill_Screen(CL_WHITE);
  TFT_Set_Pen(CL_Black, 1);
  TFT_Line(20, 220, 300, 220);
  TFT_LIne(20,  46, 300,  46);
  TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL);
  TFT_Write_Text("Temperature Sensor (One Wire)", 10, 14);
  TFT_Set_Font(&Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL);
  TFT_Write_Text("EasyMx PRO v7 for STM32", 19, 223);
  TFT_Set_Font(&Verdana12x13_Regular, CL_RED, FO_HORIZONTAL);
  TFT_Write_Text("www.mikroe.com", 200, 223);
  TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
}

void Display_Temperature(unsigned int temp2write) {
  const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
  char temp_whole;
  unsigned int temp_fraction;

  // Check if temperature is negative
  if (temp2write & 0x8000) {
    text[0] = '-';
    temp2write = ~temp2write + 1;
  }

  // Extract temp_whole
  temp_whole = temp2write >> RES_SHIFT ;

  // Convert temp_whole to characters
  if (temp_whole/100)
    text[0] = temp_whole/100  + 48;
  else
    text[0] = '0';

  text[1] = (temp_whole/10)%10 + 48;             // Extract tens digit
  text[2] =  temp_whole%10     + 48;             // Extract ones digit

  // Extract temp_fraction and convert it to unsigned int
  temp_fraction  = temp2write << (4-RES_SHIFT);
  temp_fraction &= 0x000F;
  temp_fraction *= 625;

  // Convert temp_fraction to characters
  text[4] =  temp_fraction/1000    + 48;         // Extract thousands digit
  text[5] = (temp_fraction/100)%10 + 48;         // Extract hundreds digit
  text[6] = (temp_fraction/10)%10  + 48;         // Extract tens digit
  text[7] =  temp_fraction%10      + 48;         // Extract ones digit
  text[9] = 176;

   
   
  // Print temperature on TFT
   TFT_Set_Brush(1,CL_WHITE,0,0,0,0);
   TFT_Set_Pen(CL_WHITE,1);
   TFT_Rectangle(85,100,200,140);
   TFT_Set_Font(&tahoma29x29_Bold, CL_RED, FO_HORIZONTAL);
   TFT_Write_Text(text, 85, 100);
}

void main() {


  TFT_Set_Default_Mode();
  DrawScr();

  TFT_Set_Font(&tahoma29x29_Bold, CL_BLACK, FO_HORIZONTAL);
  TFT_Write_Text("Temperature:  ", 75, 65);

  // Main loop
  do {
   Ow_Reset(&GPIOA_BASE, 3);                         // Onewire reset signal
    Ow_Write(&GPIOA_BASE, 3, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&GPIOA_BASE, 3, 0x44);                   // Issue command CONVERT_T
    Delay_ms(750);

    Ow_Reset(&GPIOA_BASE, 3);
    Ow_Write(&GPIOA_BASE, 3, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&GPIOA_BASE, 3, 0xBE);                   // Issue command READ_SCRATCHPAD

    temp =  Ow_Read(&GPIOA_BASE, 3);
    temp = (Ow_Read(&GPIOA_BASE, 3) << 8) + temp;

    // Format and display result on TFT
    Display_Temperature(temp);
   
  } while (1);

}


Would be great if someone could help me...


Uwe


Top
 Profile  
 
PostPosted: 17 Jan 2019 17:35 
Offline
mikroElektronika team
User avatar

Joined: 18 Dec 2018 10:36
Posts: 216
Hello,

Could you provide me with more details about your issue?

If you want to change the resolution to 12, you need to set:
TEMP_RESOLUTION = 12;
and
temp = ((Ow_Read(&GPIOA_BASE, 3) << 8 ) + temp) << 3;

Kind regards,
Jovana


Top
 Profile  
 
PostPosted: 19 Jan 2019 12:33 
Offline

Joined: 25 Jun 2017 18:06
Posts: 24
hi jovana,

The question is, how can I change the Resolution
to 11 bit, 10 bit or 9 bit.
My question was seemingly incomprehensible, sorry.



Greetings from Germany


Top
 Profile  
 
PostPosted: 21 Jan 2019 11:47 
Offline
mikroElektronika team
User avatar

Joined: 18 Dec 2018 10:36
Posts: 216
Hi,

If you want to set the resolution to 9, you need to set:
TEMP_RESOLUTION = 9;
and
temp = (Ow_Read(&GPIOA_BASE, 3) << 8 ) + temp;

If you want to set the resolution to 12, you need to set:
TEMP_RESOLUTION = 10;
and
temp = ((Ow_Read(&GPIOA_BASE, 3) << 8 ) + temp) << 1;

If you want to set the resolution to 11, you need to set:
TEMP_RESOLUTION = 11;
and
temp = ((Ow_Read(&GPIOA_BASE, 3) << 8 ) + temp) << 2;

If you want to set the resolution to 12, you need to set:
TEMP_RESOLUTION = 12;
and
temp = ((Ow_Read(&GPIOA_BASE, 3) << 8 ) + temp) << 3;

Kind regards,
Jovana


Top
 Profile  
 
PostPosted: 21 Jan 2019 11:55 
Offline

Joined: 25 Jun 2017 18:06
Posts: 24
hi jovanna,

Many thanks, that's exactly what I was looking for!!!
:D :D :D :D :D :D :D :D


Top
 Profile  
 
PostPosted: 21 Jan 2019 12:06 
Offline
mikroElektronika team
User avatar

Joined: 18 Dec 2018 10:36
Posts: 216
You're welcome!
If you have additional questions, feel free to ask.

Kind regards,
Jovana


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Search for:
Jump to: