Show Posts
Pages: 1 ... 54 55 [56] 57 58 ... 110
826  Using Arduino / General Electronics / Re: What are the advantage and disadvantage of Darlington pair on: December 09, 2012, 03:53:13 pm
Advantage:

Higher switching current

Disadvantage:

Multiple transistor stages means more noise, and possibly a slower response. Though this is somewhat meaningless without any specific part.


An example - you haven't given any information on purpose, so I will make up a unrealistic example to demonstrate...

For a BJT (Bipolar Junction Transistor), the current that flows into the collector is proportional to the current that flows into the base.
For example transistor x has a Beta, or current gain, of around 30. What this means is that for every 1mA that flows into the base, 30mA can flow into the collector. This is fine for smallish control signals such as that from an arduino pin. The arduino can source 20mA which means for this gain you can have a maximum collector current of around 600mA.
But what if you need to drive say 20 x 0.45A loads individually. That would require you to source ~17mA form every pin which would go far beyond the maximum power dissipation of the chip. Instead what if you used two transistors for each load. The base of the first is connected to the the arduino via a resistor to control the base current. Its collector is connected to Vcc, and its emitter is connected to the base of a second transistor. The second transistor is used to drive the load.
In this configuration lets say you put 0.5mA into the base of the first transistor. This gets amplified so that 0.5*30=15mA flows into the collector and out of the emitter from the power supply. This 15mA flows into the base of the second transistor where it is again amplified and into the second transistors collector you get 15*30=450mA.
By using this configuration for all of the loads you have cut down the amount of current the microcontroller has to source from 300mA down to 20mA, which is much better for the microcontroller.

Basically the darlington pair (or triple, or quadruple etc) allow you to get higher gains in current than a single transistor. But the whether they are needed or not depends on the application.
827  Products / Arduino Due / Due support for Nokia 6100 display on: December 08, 2012, 02:03:03 pm
The gLCD-Library has been updated to add support for the Arduino Due. Version 3.2 and future versions will support both AVR and SAM/DUE processors in a single library.

https://github.com/TCWORLD/gLCD-Library
828  Products / Arduino Due / Re: Obscure infinite for loop. on: December 08, 2012, 01:30:41 pm
Answered my own question. It would appear that char is now unsigned by default? It would be useful if that was mentioned somewhere!
829  Products / Arduino Due / Obscure infinite for loop. on: December 08, 2012, 01:28:36 pm
Any suggestions why this would result in an infinite loop? Is there something about char that has changed with regards to the due.

Code:
char i;
byte mask = 0x80;
for (i = 7;i >= 0; i--){
#ifdef _LIB_SAM_
delayMicroseconds(1);
#endif
digitalWrite(_SCLK, 0); //Clock 0
digitalWrite(_SDATA, data & mask); //Send a bit
mask >>= 1;
#ifdef _LIB_SAM_
delayMicroseconds(1);
#endif
digitalWrite(_SCLK, 1); //Clock 1
Serial.println(i);
}
830  Using Arduino / Microcontrollers / Re: Solution to PCREL error for avr25. on: November 27, 2012, 07:54:59 am
The problem this thread covers only applies to ATTiny's. Atmega328s are a totally different breed of avr.

The issue you are facing is not due to the compiler, so you should start a new thread asking for help.
831  Using Arduino / General Electronics / Re: what do you mean by biasing? on: November 25, 2012, 06:09:45 am
Your english is good enough to ask here.
Just thought I'd point out that you get 1.7 million google hits if you search 'biasing in transistor', and the first hit has information on questions 1-3.

Is it just me or does this sound like a school/uni assignment.
832  Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 23, 2012, 07:55:52 am
It looks like there is more to this than meets the eye. For example there are two types of write - one which writes commands, one which writes registers. As such there are now two write functions.

Secondly, it looks like you need to send a reset command before you can use it.

Thirdly you wanted continuous conversion mode, so that needs to be set.

As for which mode it is, the datasheet seems totally ambiguous. In the diagrams on page 12, compare SDI Write and SDO Read diagrams, in the first you will see the additional falling edge I mentioned, in the second you will see none. So who knows which mode it is - could be 0 could be 3 - try both.

Finally make sure that the MODE pin on the IC is connected to ground.

Code:
#include <SPI.h>

union FourByte{
    struct {
      unsigned long value:24; //24bit register values go in here
      byte command:8; //8bit command goes in here.
    };
    byte bit8[4]; //this is just used for efficient conversion of the above into 4 bytes.
};

void setup(){
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE3); //I believe it to be Mode3
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  pinMode(SS, OUTPUT); //not really necessary as it is done by the SPI library.
  digitalWrite(SS, HIGH);  
  
  Serial.begin(9600);
  
  unsigned long check = SPI_read(0x00); //read the config register.
  Serial.print("Config = ");
  Serial.println(check);
  
  //Software reset:
  SPI_writeCommand(0x80);
  
  unsigned long status;
  do {
    status = SPI_read(0b00011110); //read the status register
    status &= (1UL<<23);
  } while (!status); //keep checking until DRDY bit gets set.

  SPI_writeCommand(0xE8); //Set continuous conversion mode  
  
  
  check = SPI_read(0x00); //read the config register.
  Serial.print("Config = ");
  Serial.println(check);

/*
  //example of writing a register
  union FourByte data;
  data.command = 0b01000000; //Write to config register
  data.value = 1; //This is the default value from datasheet, just using it as an example.
  SPI_writeRegister(data);*/
}

void loop(){
  delay(1000);
    //example of reading data
  unsigned long voltage = SPI_read(4);//Instantaneous Voltage Channel 1
  Serial.print("Voltage = ");
  Serial.println(voltage);
}

void SPI_writeCommand(byte command) {
  digitalWrite(SS,LOW); //SS goes low to mark start of transmission
  union FourByte data = {0xFEFEFE,command}; //generate the data to be sent, i.e. your command plus the Sync bytes.
  for(char i = 3; i >= 0; i--){
    SPI.transfer(data.bit8[i]); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 24bit value.
  }
  digitalWrite(SS,HIGH);
}
void SPI_writeRegister(union FourByte data) {
  digitalWrite(SS,LOW); //Using CS pin, so sync1/sync0 bytes not needed
  for(char i = 3; i >= 0; i--){
    SPI.transfer(data.bit8[i]); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 24bit value.
  }
  digitalWrite(SS,HIGH);
}

unsigned long SPI_read(byte command){
  digitalWrite(SS,LOW); //SS goes low to mark start of transmission
  union FourByte data = {0xFEFEFE,command}; //generate the data to be sent, i.e. your command plus the Sync bytes.
  for(char i = 3; i >= 0; i--){
    data.bit8[i] = SPI.transfer(data.bit8[i]); //send the data whilst reading in the result
  }
  digitalWrite(SS,HIGH); //SS goes high to mark end of transmission
  return data.value; //return the 24bit value recieved.
}

Could you try running that with:
Code:
SPI.setDataMode(SPI_MODE3);

And with
Code:
SPI.setDataMode(SPI_MODE0);

In each case, what value is returned on the Serial Monitor for the line "Config = "
833  Using Arduino / Microcontrollers / Re: SPI 32-bits Fetching data for IC on: November 22, 2012, 04:09:38 pm
I think this thread has spun off from this one:
http://arduino.cc/forum/index.php/topic,133133.15.html
In which case in my original code, this line:
Code:
data.bit8 = SPI.transfer(data.bit8);

was:
Code:
data.bit8[i] = SPI.transfer(data.bit8[i]);

In which four special bytes are sent to recieve 3 bytes in return (the first of the four recieved bytes gets ignored when the function returns the 24bit field in the struct)

similarly in the write function, this:
Code:
    SPI.transfer(data.bit8); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 24bit value.
was/should be
Code:
    SPI.transfer(data.bit8[i]); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 24bit value.
834  Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 22, 2012, 02:47:47 pm
I also got it from vendor smiley.All I do is read the data sheet and managing for the code based on the data sheet.But I'm also still on the way so we can help each other out.

@Tom BTW What's this line also...Thanks a lot

Code:
data.value = 1; //This is the default value from datasheet, just using it as an example.

Basically that is setting the value you want to write to a register.

The bit of code relavent to that snippit is:
Code:
 //example of writing data
  union FourByte data;
  data.command = 0b01000000; //Write to config register
  data.value = 1; //This is the default value from datasheet, just using it as an example.
  SPI_write(data);

In the code, the command is set to write to the config register (0b01000000 from the datasheet - page 26), and then the value to write to that register is 1 (if you look at the list of commands in the datasheet it shows that the default value for the config register is 1, this was just an example of usage, not a requirement).

When you are reading a register, the lower three bytes should be 0xFEFEFE as you pointed out. This is done in the SPI_Read() function for you.



@Paradigm yes,I'm on the same boat as you.  smiley and I used Energy IC diagram as in the data sheet page 42 to join the Arduino Uno....working out on the program..

@Tom  Thanks for the correction.. How can I print the voltage?I mean when I print out,the voltage value remains at 0.Should this line be in the loop?
Code:
unsigned long voltage = SPI_read(4);//Instantaneous Voltage Channel 1


That is an example of how to read a register, it doesn't actually do anything with the returned value. You could do something like this:

Code:
void loop() {
  delay(1000);
  unsigned long voltage = SPI_read(4);//Instantaneous Voltage Channel 1
  Serial.println(voltage); //print the voltage to the serial monitor (you will need to have called Serial.begin(...) in the setup() for it to work)
}


Quote
Also, it is definitely MODE_3. The datasheet talks about the SDI setup time before rising edge which is indicative of MODE_3 which the timing diagrams confirm.
How do you figure that? The way I see it, the timing diagram shows the capture is on the first rising edge after the CS goes LOW. That timing specification is marked (on the write timing) as "t3" (time required between the CS Falling and SCLK Rising) (edit: and "t6" on the read timing).

The read timing shows this best. SCLK is idle LOW with clock pulses going HIGH. That is SPI Mode 0.
http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

Are we having fun yet?  smiley


The way I see the timing diagrams, it doesn't matter where the clock IDLEs in SPI. The clock is high when/as the SS line goes low. So we have:

SCLK is high.
SS drops low.
SCLK drops low.
MOSI is set to the correct value
SCLK rises high -> data is clocked in on the rising edge

All of that is indicative of MODE3.

Another way of putting it is that there is always a falling edge of SCLK before the first rising edge on which data is clocked - this is MODE3.
835  Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 22, 2012, 05:49:09 am
You are correct that the clock for the IC should be 4MHz. However at 4MHz, the serial clock frequency for its SPI interface is limited to a maximum of 2MHz, which is specified on page 11 of the datasheet.

As the Uno runs at 16MHz, then
SPI_CLOCK_DIV2 = 8MHz,
SPI_CLOCK_DIV4 = 4MHz,
SPI_CLOCK_DIV8 = 2MHz,
SPI_CLOCK_DIV16 = 1MHz.

As such you will see this line in the code in my last post:
  SPI.setClockDivider(SPI_CLOCK_DIV16);

So that the SPI interface will run at 1MHz. It is usually best to run below the maximum value which is why I suggest using 1MHz not 2MHz.
836  Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 22, 2012, 05:04:52 am
Right, all of the code appears to be doing what is expected, however I have just had it up on the oscilloscope and the default SCLK rate (8MHz) is far far faster than the chips absolute maximum SCLK rate (2MHz).

Also, it is definitely MODE_3. The datasheet talks about the SDI setup time before rising edge which is indicative of MODE_3 which the timing diagrams confirm.

Try this:
Code:
#include <SPI.h>

union FourByte{
    struct {
      unsigned long value:24; //24bit register values go in here
      byte command:8; //8bit command goes in here.
    };
    byte bit8[4]; //this is just used for efficient conversion of the above into 4 bytes.
};

void setup(){
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE3); //I believe it to be Mode3
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  pinMode(SS, OUTPUT); //not really necessary as it is done by the SPI library.
  digitalWrite(SS, HIGH);
  //Page
  //example of reading data
  unsigned long voltage = SPI_read(4);//Instantaneous Voltage Channel 1
  
  //example of writing data
  union FourByte data;
  data.command = 0b01000000; //Write to config register
  data.value = 1; //This is the default value from datasheet, just using it as an example.
  SPI_write(data);
}

void loop(){
  
}

void SPI_write(union FourByte data) {
  digitalWrite(SS,LOW); //Using CS pin, so sync1/sync0 bytes not needed
  for(char i = 3; i >= 0; i--){
    SPI.transfer(data.bit8[i]); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 24bit value.
  }
  digitalWrite(SS,HIGH);
}

unsigned long SPI_read(byte command){
  digitalWrite(SS,LOW); //SS goes low to mark start of transmission
  union FourByte data = {0xFEFEFE,command}; //generate the data to be sent, i.e. your command plus the Sync bytes.
  for(char i = 3; i >= 0; i--){
    data.bit8[i] = SPI.transfer(data.bit8[i]); //send the data whilst reading in the result
  }
  digitalWrite(SS,HIGH); //SS goes high to mark end of transmission
  return data.value; //return the 24bit value recieved.
}
837  Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 22, 2012, 04:33:55 am
@Jay

You are correct about the changes from byte to char in the for loops, that was a typo on my end. Also setting SS high at the beginning is necessary (though setting it to an output is done by the SPI library).

One thing I have noticed is that you are trying to use SPI mode 0, and I believe the IC to be SPI mode 3 (data is read on the first rising edge after a falling one according to the timing diagrams).


@Paradigm

The union works by placing an array of 4 bytes in the same memory location as the struct. The struct contains a 24bit variable and a byte variable.
 Due to the way unions work this basically means that the byte variable 'command' is stored at the same place as the element 3 in the array. Similarly the variable 'value' is stored in the same memory space as the three other bytes in the array (elements 0,1,2).
Basically what this means is that you can convert between the array and the struct without doing any calculations, making it a very efficient method.

I will have a play with the code to see if I can find anything which may be causing a problem.
838  Using Arduino / Project Guidance / Re: LED Gurus? on: November 20, 2012, 07:23:24 pm
For maximum power density, you would need to start looking at rechargeable Li-Po batteries like those used for RC planes and helicopters.

As a gauge for how long they last, a battery rated for 1100mAH would supply 1100mA for an hour, or in your case 140mA for 1100mAH/140mA = 7.9Hours.
839  Using Arduino / Project Guidance / Re: LED Gurus? on: November 20, 2012, 05:51:51 pm
Yup, Forward Current (aka If) = 140 [mA] = 0.14 [A]. Forward Voltage (aka Vf) is somewhere in the region of 1.4 [V] to 1.5 [V], so I would work on the theory that it is 1.45 [V] (the actual voltage will depend on the LED, temperature, current), but this approximate figure should be good enough.

If we do the math, 5 diodes in series x 1.45 [V] each = 7.25 [V] dropped across the diodes. For a nominal 9 [V] supply, this leaves 9-7.25=1.75 [V] across your resistor. V=IR, so R = V/I = 1.75/0.14 = 12.5 [Ohm]. You will need an minimum P=IV = 0.14*1.75 = 0.245 [W] rated resistor.

However... A 9V battery supplying 140mA will run flat very very very quickly. You would be lucky if you got half an hour out of it. The other thing is that you would be wasting a lot of energy in that resistor.
840  Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 20, 2012, 04:27:18 pm
Modified my example from before based on the datasheet:
Code:
#include <SPI.h>

union FourByte{
    struct {
      unsigned long value:24; //24bit register values go in here
      byte command:8; //8bit command goes in here.
    };
    byte bit8[4]; //this is just used for efficient conversion of the above into 4 bytes.
};

void setup(){
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE3); //I believe it to be Mode3
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  pinMode(SS, OUTPUT); //not really necessary as it is done by the SPI library.
  digitalWrite(SS, HIGH);
  //Page
  //example of reading data
  unsigned long voltage = SPI_read(4);//Instantaneous Voltage Channel 1
  
  //example of writing data
  union FourByte data;
  data.command = 0b01000000; //Write to config register
  data.value = 1; //This is the default value from datasheet, just using it as an example.
  SPI_write(data);
}

void loop(){
  
}

void SPI_write(union FourByte data) {
  digitalWrite(SS,LOW); //Using CS pin, so sync1/sync0 bytes not needed
  for(char i = 3; i >= 0; i--){
    SPI.transfer(data.bit8[i]); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 24bit value.
  }
  digitalWrite(SS,HIGH);
}

unsigned long SPI_read(byte command){
  digitalWrite(SS,LOW); //SS goes low to mark start of transmission
  union FourByte data = {0xFEFEFE,command}; //generate the data to be sent, i.e. your command plus the Sync bytes.
  for(char i = 3; i >= 0; i--){
    data.bit8[i] = SPI.transfer(data.bit8[i]); //send the data whilst reading in the result
  }
  digitalWrite(SS,HIGH); //SS goes high to mark end of transmission
  return data.value; //return the 24bit value recieved.
}
Pages: 1 ... 54 55 [56] 57 58 ... 110