Show Posts
Pages: 1 ... 70 71 [72] 73 74 ... 114
1066  Using Arduino / Project Guidance / Re: Advice for a newbie in DSP: which board could work for me? on: November 10, 2012, 07:39:52 pm
An Arduino or any other generic microcontroller isn't going to do that.
You will need a processor which has instructions specifically designed for DSP.

Pete
1067  Using Arduino / Programming Questions / Re: 1 Wire DS18B20 on: November 10, 2012, 11:14:56 am
Let's start with something that is known to work. The code below works on a Duemilanove wired as described here.
For parasite power the DS18B20 is wired so that the two outer leads are connected to ground. The middle lead has a 1.5k pullup resistor to +5V. The middle lead is also connected to pin 8 on the Arduino. Then run this code:
Code:
#include <OneWire.h>

// http://datasheets.maxim-ic.com/en/ds/DS18B20.pdf

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
// The two bugs in the conversion of the temperature have been fixed.
// The first bug didn't handle the precision correctly for anything
// other than 12 bits.
// The second bug was that the temperature was converted as an
// unsigned int which meant that it wouldn't convert a negative
// temperature correctly.

OneWire  ds(8);

// SELECT a precision here
// t_precision #bits -  delay(ms)
//      0        9   -   93.75
//      1       10   -  187.5
//      2       11   -  375
//      3       12   -  750
#define ds18b20_PRECISION 2
unsigned char t_precision = ds18b20_PRECISION;

// DS18B20 address data
byte addr[8][8];
byte data[12];
const unsigned char t_mask[4] = {
  0x7, 0x3, 0x1, 0x0};

void print_rom(byte *p)
{
  Serial.print("ROM =");
  for(int i = 0; i < 8; i++) {
    Serial.write(' ');
    if(*p < 10)Serial.print(" ");
    Serial.print(*p++, HEX);
  }
  Serial.println(" "); 
}


void setup(void)
{
  byte i,numdev;
  byte present = 0;
  byte type_s;
  float celsius, fahrenheit;

  Serial.begin(9600);
  i = 0;
  Serial.println("");
  Serial.println("");
  while(ds.search(addr[i])) {
    if (OneWire::crc8(addr[i], 7) != addr[i][7]) {
      print_rom(addr[i]);
      Serial.println("CRC is not valid! - ignored");
      continue;
    }
    print_rom(addr[i]);
    i++;
  }
  if(i == 0) {
    Serial.println("Nothing found");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  numdev = i;

  for(int j=0;j<numdev;j++) {
    Serial.println();
    // This clears the alarm registers and sets the precision
    ds.select(addr[j]);   
    ds.write(0x4E,0);
    // write zero into the alarm registers
    ds.write(0,0);
    ds.write(0,0);
    // and write t_precision into the configuration register
    // to select the precision of the temperature
    ds.write(t_precision << 5,0);
    // Write them to the EEPROM
    ds.write(0x48,1);

    delay(20);
    ds.depower();
    // the first ROM byte indicates which chip
    switch (addr[j][0]) {
    case 0x10:
      Serial.print("  Chip = DS18S20 ");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.print("  Chip = DS18B20 ");
      type_s = 0;
      break;
    case 0x22:
      Serial.print("  Chip = DS1822  ");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      continue;
    }
    print_rom(addr[j]);

    ds.reset();
    ds.select(addr[j]);
#define PARASITE
#ifdef PARASITE
    ds.write(0x44,1);         // start conversion, with parasite power on at the end
#else
    ds.write(0x44,0);
#endif
    delay(1000);

    // we might do a ds.depower() here, but the reset will
    // take care of it.
    present = ds.reset();
    ds.select(addr[j]);   
    ds.write(0xBE,0);         // Read Scratchpad

    Serial.print("present=");
    Serial.print(present,HEX);
    Serial.print(" prec=");
    Serial.print(t_precision);
    Serial.print(" Data = ");
    for ( i = 0; i < 9; i++) {           // we need 9 bytes
      data[i] = ds.read();
      Serial.print(data[i], HEX);
      Serial.print(" ");
    }
    Serial.print(" CRC=");
    Serial.print(OneWire::crc8(data, 8), HEX);
    Serial.println();

    // BUG - this must NOT be unsigned otherwise it won't handle
    // negative temperatures.
    int raw = (data[1] << 8) | data[0];
    // The original version of this code had a bad bug here which
    // only worked when it was reading with 12-bit precision.
    // This code fixes it (and emailed the author).
    //  int cfg = (data[4] & 0x60) >> 5;
    // For now, override the precision stored in the device until I can
    // figure out why the code is not setting it.
    int cfg = t_precision;
    raw &= ~t_mask[cfg];
    celsius = (float) raw / 16.0;
    Serial.print("  Temperature = ");
    Serial.print(celsius,4);
    Serial.println(" Celsius");
    //  fahrenheit = celsius * 1.8 + 32.0;
    //  Serial.print(fahrenheit);
    //  Serial.println(" Fahrenheit");

  } // END OF FOR J LOOP

}


void loop(void)
{
}

It produces this output:
Code:
ROM = 28 B9 E6 79  3  0  0 16

  Chip = DS18B20 ROM = 28 B9 E6 79  3  0  0 16
present=1 prec=2 Data = 53 1 4B 46 7F FF D 10 E9  CRC=E9
  Temperature = 21.1250 Celsius

This code scans the bus so you don't need to know the address of the chip.

Pete
1068  Using Arduino / Programming Questions / Re: 1 Wire DS18B20 on: November 08, 2012, 08:42:49 pm
Quote
which is what the Dallas one-wire system is all about and, without them, you would probably sink at the mooring.
The example code posted by the OP in his first message doesn't need a device address. It checks all devices on the I2C and looks for a DS18B20 and then talks that. All that is needed to get that code working is to apply the two fixes at http://www.pjrc.com/teensy/td_libs_OneWire.html#bugs

Pete
1069  Using Arduino / General Electronics / Re: Hard Maths question on: November 08, 2012, 09:48:38 am
Code:
new_result = result - .014
?

Pete
1070  Using Arduino / Programming Questions / Re: 1 Wire DS18B20 on: November 08, 2012, 09:44:59 am
See the Known Bugs section on the PJRC page. You have to apply those two patches to the code for it to work properly.

Pete
1071  Development / Other Hardware Development / Re: Teensy 3.0 on: November 07, 2012, 08:59:37 pm
Quote from: Coding Badly
Using float or double?
float.


@Nantonos. Thanks for the info. I've now found the forum and also discovered just how trivial it is to run a sketch overclocked at 96MHz.
I suspect that sorting out the DSP stuff is gonna be a bit less than trivial though :-)

Pete
1072  Development / Other Hardware Development / Re: Teensy 3.0 on: November 07, 2012, 07:02:36 pm
I tried a benchmark of my own using a function which computes the bearing between two locations specified as lat/long. It produces essentially the same kind of timing as seen before.
In summary, compared to a Duemilanove (=2009) the result of calling the function 10000 times is:
2009 @ 16MHz 12.57secs
T3    @ 48MHz   8.30 secs
T3    @ 96MHz   7.82 secs

The interesting thing I noted was the difference in the size of the code.
The Duemilanove code is 4764 bytes whereas the T3 code is 19984 bytes! I presume that the T3 is hauling in different libraries but it seems to be a bit excessive. OTOH it is 19984 bytes of a 131,072 byte maximum so there's plenty of room to spare :-)

Pete
1073  Using Arduino / Project Guidance / Re: Why are all of these buttons acting like they are the same? on: November 03, 2012, 04:28:50 pm
... and a diagram of how the buttons are wired up.
It sounds to me like they are all wired to one pin or perhaps to all of the pins.

Pete
1074  Using Arduino / Storage / Re: Random Error Codes on: November 01, 2012, 06:40:39 pm
If a generic SDFat example fails then it does suggest that either there's a hardware (e.g. wiring/soldering) problem or the SD card itself is at fault.

Pete
1075  Using Arduino / Storage / Re: Random Error Codes on: November 01, 2012, 03:07:53 pm
I'm not too familiar with SdFat but haven't you declared sdout improperly?
Shouldn't it be declared as:
Code:
SdFile sdout;

Pete
1076  Using Arduino / Storage / Re: Random Error Codes on: October 31, 2012, 10:04:23 pm
See: http://www.arduino.cc/playground/Code/AvailableMemory

Pete
1077  Using Arduino / Storage / Re: Random Error Codes on: October 31, 2012, 09:25:31 pm
My guess is that you are running out of SRAM. Which Arduino are you using?

Pete
1078  Using Arduino / Programming Questions / Re: Passing an undeclared array to a function on: October 31, 2012, 12:34:08 pm
Quote
My goal is to be able to call a specific function many times successively with a new/undeclared array as a parameter being passed
Your goal is to write a C/C++ program using a syntax that isn't supported by the language? Why? What has this got to do with writing a program to solve a particular problem?

Quote
I'm hoping I don't have to declare it beforehand (doubling the number of lines of code)
Again, why is this a problem? If it requires a few more lines of code to get the job done, then that is what you have to do.

Pete
1079  Using Arduino / Programming Questions / Re: unexpected itoa() behavior on: October 29, 2012, 06:37:40 pm
Serial.print(x) prints the decimal value of the variable and itoa(x) converts the variable to a decimal string. Either way, you end up with the decimal representation of the integer. What you need is to print the integer as a single character and that is what Serial.write(x) does.

Pete
1080  Using Arduino / Programming Questions / Re: unexpected itoa() behavior on: October 29, 2012, 06:28:35 pm
Try replacing this:
Code:
    Serial.write(mystr);
with this:
Code:
    Serial.write(x);

Pete
Pages: 1 ... 70 71 [72] 73 74 ... 114