Power consumption

Questions for programming 8051 microcontrollers in C or assembly using SDCC

Re: Power consumption

Postby mbee » Mon Feb 16, 2015 2:11 pm

Hi Vittaly,

OK it seems weird that the with the same board as I am using you're not able to get down to these low currents. Your multimeter might be uncalibrated?

Anyway. I had some problems getting 1wire to work. Could you post your code to your ds18b20 temperature sensor implementation?
mbee
 
Posts: 3
Joined: Wed Feb 11, 2015 9:32 am

Re: Power consumption

Postby Vittaly » Mon Feb 16, 2015 6:50 pm

mbee wrote:Hi Vittaly,
Anyway. I had some problems getting 1wire to work. Could you post your code to your ds18b20 temperature sensor implementation?


Hi mbee,
There is code I use for working with ds18B20. First of all some precedures:

Code: Select all
#define DSPIN GPIO_PIN_ID_P0_3
void OneWireReset()
{
     gpio_pin_val_clear(DSPIN);
 gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_OUTPUT);
     delay_us(500);
gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_INPUT);
   
     delay_us(500);
}

void OneWireOutByte(uint8_t d)
{
   uint8_t n;
interrupt_control_global_disable();
   
   for(n=8; n!=0; n--)
   {
      if ((d & 0x01) == 1)
      {
    gpio_pin_val_clear(DSPIN);
    gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_OUTPUT);
         delay_us(2); //5
    gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_INPUT);
         delay_us(60);
      }
      else
      {
    gpio_pin_val_clear(DSPIN);
    gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_OUTPUT);
         delay_us(60);
    gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_INPUT);

      }
      d=d>>1;
   }
   interrupt_control_global_enable();
}


uint8_t OneWireInByte()
{
    uint8_t d=0, n,b=0;
  interrupt_control_global_disable();

    for (n=0; n<8; n++)
    {
   gpio_pin_val_clear(DSPIN);
   gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_OUTPUT);
        delay_us(2); // 5
   gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_INPUT);
        delay_us(2); // 5
   b = gpio_pin_val_read(DSPIN);
        delay_us(50);
        d = (d >> 1) | (b<<7);
    }
    interrupt_control_global_enable();
    return(d);
}


and then code in main body:


Code: Select all
uint8_t SignBit;
uint8_t DSdata[2];
int TReading;

OneWireReset();
     OneWireOutByte(0xcc);
     OneWireOutByte(0x44);
     //strong
     
      // gpio_pin_val_set(DSPIN);
      //gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_OUTPUT);
       delay_ms(1000);
       //gpio_pin_configure(DSPIN, GPIO_PIN_CONFIG_OPTION_DIR_INPUT);
       //gpio_pin_val_clear(DSPIN);
     
     OneWireReset();
     OneWireOutByte(0xcc);
     OneWireOutByte(0xbe);

     DSdata[0] = OneWireInByte();
     DSdata[1] = OneWireInByte();

     //TReading = (int)(DSdata[1] << 8) + DSdata[0];
     TReading = (DSdata[1] << 8) + DSdata[0];
     SignBit = TReading & 0x8000;
     if (SignBit) TReading = (TReading ^ 0xffff) + 1;
     temperature_Sensor =((6 * TReading) + TReading / 4)/10;
Vittaly
 
Posts: 7
Joined: Wed Jan 14, 2015 12:12 pm

Previous

Return to 8051 Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron