Show Posts
Pages: [1] 2 3 ... 19
1  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: March 01, 2014, 05:48:27 am
Marvellous, thanks for explaining - that's incredibly useful, I can't believe I didn't know how to do that ;-)

Have a good weekend.
2  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: March 01, 2014, 04:23:48 am
You have of course cracked this - thank you again.

So I understand..... putting 'float' at the start of the calculation effectively converts any ints in the formula to floats?
3  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: March 01, 2014, 04:10:10 am
Hmmm, I have one more question which is very odd to my eyes but I am doing something simple wrong :-)

When I evaluate the following code temp returns a value of -46 whereas it should be 18.45 according to my calculator?  I guess I need to do this differently.....

Code:
float temp;
int tempCount = 701;
temp=(((tempCount*200)/2048)-50);
4  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 06:47:46 pm
Star - thank you :-)

I've learnt alot tonight - cheers.
5  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 06:25:27 pm
Sorry, I'm not completely following how this works.... however

The result should be with the bits we need to use in BOLD:
Binary values are those recieved, Binary values in BOLD are those to use and HEX values from the Binary values to use:
BYTE1 0x20 = 10100000
BYTE2 0x04 = 00100000
Gives 0010000000000100 = 0x2004

&

BYTE3 0x5B = 01011011
BYTE4 0xC0 = 11010100
Gives 01011011110 = 0x2DE

6  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 05:53:59 pm
Almost :-)

int Pressure = (B_1 << smiley-cool | B_2;
is correct and gives 0x2004

int Temp = (B_3 << smiley-cool | B_4;
isn't correct and should give 0x2DE ?
7  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 05:36:45 pm
Hi,

Here is my code, on an Arduino 328:
Code:
 int tempReading = 0;
  int pressureReading = 0;
  int PMSB=0x0;
  int PLSB=0x0;
  int TMSB=0x0;
  int TLSB=0x0;

  Wire.beginTransmission(0x50);
  Wire.endTransmission();
  Wire.requestFrom(0x50,4);
  PMSB = Wire.read();
  PLSB = Wire.read();
  TMSB = Wire.read();
  TLSB = Wire.read();

  PMSB = (PMSB & 0x3F);
  TLSB = (TLSB & 0xE0);
  pressureReading = (PMSB + PLSB);
  tempReading = (TMSB + TLSB);
8  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 05:17:59 pm
Thanks for helping out folks - I'm very close to seeing this working now....

My 4 BYTES come in as:
1: A0
2: 04
3: 5B
4: D4

I can mask them thansk to you folk giving:
1: 20
2: 04
3: 5B
4: C0

No the problem comes when I try to join BYTE1 to BYTE2 & BYTE3 to BYTE4

I should get the following answer:
1+2 = 0x2004
3+4 = 0x2DE

With this code I get the wrong answer for some reason?

Code:
INT pressureReading = ((BYTE1*256) + BYTE2);
INT tempReading = ((BYTE3*256) + BYTE4);
9  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 03:24:13 pm
Cool - I understand how that works :-)

I now have this but alas no joy yet:

Code:

  PMSB = Wire.read();
  PLSB = Wire.read();
  TMSB = Wire.read();
  TLSB = Wire.read();

  PMSB = (PMSB & 00111111);  //Mask off first two bits
  TLSB = (TLSB & 11100000);  //Mask off last five bits
  pressureReading = ((PMSB*256) + PLSB);  //Shift PMSB left 8 bits and add PLSB as INT
  tempReading = ((TMSB*256) + TLSB);  //Shift TMSB left 8 bits and add TLSB as INT
 
10  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 03:06:21 pm
.... fab - may I ask how I would mask these bytes please  smiley-red
11  Topics / Science and Measurement / Re: SODAQ - a nice Arduino Low Power Wireless Data Logging Project on: February 28, 2014, 02:44:25 pm
No news yet - I think we will have them soon :-)
12  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 02:39:39 pm
PS, this is the I2C request and response:
13  Using Arduino / Programming Questions / Bit stuck on bit manipulations ? on: February 28, 2014, 02:29:44 pm
Hi,

Wondering if I may ask for a little help with this bit maniulation problem?

I have an I2C sensor which returns 4 bytes but I need to extract 14 bits from the first two and 11 bits from the second two:

Byte 1: 00101100 //use last 6 bits
Byte 2: 11001101  //use all 8 bits
Byte 3: 01011100 //use all 8 bits
Byte 4: 11100000 //use first 3 bits

Aiming for:
Byte1 + Byte2 = Value 1: 10110011001101 = 11469 in Decimal
&
Byte3 + Byte4 = Value 2: 01011100111 = 743 in Decimal

My code currently looks like this but not sure how to manipulate the bits to get the above format correct?

The byte values returned at the moment are (values should be different to the example above):

PMSB = 10100000
PLSB =  100
TMSB = 1011011
TLSB = 1110100

Code:
 int value 1;
  int value 2;
  byte PMSB;
  byte PLSB;
  byte TMSB;
  byte TLSB;
  Wire.beginTransmission(0x50);
  Wire.endTransmission();
  Wire.requestFrom(0x50,4);
  PMSB = Wire.read();
  PLSB = Wire.read();
  TMSB = Wire.read();
  TLSB = Wire.read();
  value1 = ((PMSB << 8) | PLSB);
  value2 = ((TMSB << 8) | TLSB);


14  Using Arduino / Programming Questions / Re: Date/Time for RTC as seconds since 1/1/2000 on: December 10, 2013, 04:12:32 pm
Well I think your right, hacking the Library like this will trip me up in the future - I would prefer to set those register bits from the sketch but really not sure how to do that?
15  Using Arduino / Programming Questions / Re: Date/Time for RTC as seconds since 1/1/2000 on: December 10, 2013, 03:55:20 pm
Hi Crossroads,

Thanks, I will look at that.  Also, looking at the datasheets it looks as if there are some alarm modes which are not implemented in the Library such as 'When Minutes Match' & 'When Minutes and Seconds Match' - this would suffice as I could just increment minutes and seconds and not worry about what happens to hours, day, months etc - So if I understand right I have modified bit 7 in the registers below to enable 'When Minutes and Seconds Match' - might be a bit of a rough code edit but it could work :-)

Code:
//Enable HH/MM/SS interrupt on /INTA pin. All interrupts works like single-shot counter
void DS3231::enableInterrupts(uint8_t hh24, uint8_t mm, uint8_t ss)
{
    unsigned char ctReg=0;
    ctReg |= 0b00011101;
    writeRegister(DS3231_CONTROL_REG, ctReg);     //CONTROL Register Address

    writeRegister(DS3231_AL1SEC_REG,  0b00000000 | bin2bcd(ss) ); //Clr AM1
    writeRegister(DS3231_AL1MIN_REG,  0b00000000 | bin2bcd(mm)); //Clr AM2
    writeRegister(DS3231_AL1HOUR_REG, (0b10000000 | (bin2bcd(hh24) & 0b10111111))); //Clr AM3
    writeRegister(DS3231_AL1WDAY_REG, 0b10000000 ); //set AM4
}
Pages: [1] 2 3 ... 19