Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

George Antoniadis

Member Since 04 Apr 2011
Offline Last Active Feb 18 2013 08:15 AM
-----

Topics I've Started

PowerState.RebootDevice soft/hard option.

14 October 2011 - 08:49 AM

I'm using the
PowerState.RebootDevice
method and I was wondering what the differences between the soft/hard options are and when each should be used.

Thanks! :)

Mono bootloader and 4.2beta

13 September 2011 - 10:39 AM

I was playing around with the Mono Bootloader that allows running PEs from the SD card.
http://forums.netdui...nd-sample-apps/

Everything works as excepted on the 4.1.1beta firmware but the Bootloader dies when being run against the 4.2beta.
The problem seems to be that some stuff have been removed (maybe for the sake of ram/rom?).

netduinoAppClassInstance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap("MonoNetduinoApp, Version=1.0.0.0", "MonoNetduinoApp.Program");
Gets caught with:
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'MonoNetduinoApp'
A first chance exception of type 'System.NotImplementedException' occurred in mscorlib.dll

Any ideas if the bootloader could work some how on the 4.2b?

Thanks! :)

Netduino with 24Bit ADC (LTC2400) Help.

12 May 2011 - 08:19 AM

I'm fairly new with netduino, had mine (plus) for couple of days now and I'm very pleased with it so far.
My electronics skills are pretty basic so please bare with me and my pretty long rant :)

Any help/hints are greatly appreciated.

I've build a 24bit ADC using the LTC2400 based on the this.
This was initially made for arduino on which works like a charm but now I need to move this to my netduino plus.

Looking around in the LTC2400 datasheet for the SPI configuration values helped a bit but some things like "SS Active", "Clock idle" and "Clock rate" are still missing as I am not sure what I should be looking for.

I've created a test project based on the MCP320X Test by GDSever but ended up changing most of the ReadADC method to match the code from my arduino project (provided in the end of the post).

The end results is pretty random, some times it seems to work (usually when voltage is around 1.6v for some weird and most likely random reason).
Let me try to explain what happens.

byte[] writeArray = new byte[];
byte[] readArray = new byte[8];
spi.WriteRead(writeArray, readArray);

This populated the readArray with data on the first 4 bytes and the rest are full of 1111s;
To me this seems wrong, could it be due to SPI configuration values?

Due to the fact that the ADC is 24 bit, the data is split into 4 bytes.
The first byte seems to contain the integer's sign (-/+) and some leading junk data.
The last byte seems have 4 bits junk data in the end.

Does SPI.WriteRead do something with the binary data? Reverse their order or something?

What else might I be missing?

C# ReadADC method.
public Int32 ReadADC(uint numSamples = 1)
{
    Int32 ltw = new byte();

    byte[] writeArray = new byte[4];
    byte[] readArray = new byte[8];

    // Send the command and read the response.
    SPI.Configuration config = CurrentConfig();
    using (SPI spi = new SPI(config))
    {
        Thread.Sleep(100);
        spi.WriteRead(writeArray, readArray);

        ltw = 0;

        bool sig = false;
        if ((readArray[0] & 0x20) == 1)
        {
            sig = true;
        }

        readArray[0] &= 0x1F;
        ltw |= readArray[0];
        if (sig)
        {
            ltw |= 0xF0;
        }
        ltw <<= 8;

        ltw |= readArray[1];
        ltw <<= 8;

        ltw |= readArray[2];
        ltw <<= 8;

        ltw |= readArray[3];

        ltw = ltw / 16;

        spi.Dispose();
    }

    return ltw;

}

Arduino code.
/* LTC2400 24 Bit ADC Test
* Connect an LTC2400 24 Bit ADC to the Arduino Board in SPI Mode
*
*
*
* KHM 2009 /  Martin Nawrath
* Kunsthochschule fuer Medien Koeln
* Academy of Media Arts Cologne

*/
#include <Stdio.h>

#ifndef cbi
#define cbi(sfr, bit)     (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit)     (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#define LTC_CS 2         // LTC2400 Chip Select Pin  on Portb 2
#define LTC_MISO  4      // LTC2400 SDO Select Pin  on Portb 4
#define LTC_SCK  5       // LTC2400 SCK Select Pin  on Portb 5

void setup() {

 cbi(PORTB,LTC_SCK);      // LTC2400 SCK low
 sbi (DDRB,LTC_CS);       // LTC2400 CS HIGH

 cbi (DDRB,LTC_MISO);
 sbi (DDRB,LTC_SCK);

 Serial.begin(57600);
 // init SPI Hardware
 sbi(SPCR,MSTR) ; // SPI master mode
 sbi(SPCR,SPR0) ; // SPI speed
 sbi(SPCR,SPR1);  // SPI speed
 sbi(SPCR,SPE);   //SPI enable

 Serial.println("LTC2400 ADC Test");

}
float volt;
float v_ref=3.0;          // Reference Voltage, 5.0 Volt for LT1021 or 3.0 for LP2950-3

long int ltw = 0;         // ADC Data ling int
int cnt;                  // counter
byte b0;                  //
byte sig;                 // sign bit flag
char st1[20];             // float voltage text

/********************************************************************/
void loop() {

 cbi(PORTB,LTC_CS);             // LTC2400 CS Low
 delayMicroseconds(1);
 if (!(PINB & (1 << PB4))) {    // ADC Converter ready ?
   //    cli();
   ltw=0;
   sig=0;

   b0 = SPI_read();             // read 4 bytes adc raw data with SPI
   if ((b0 & 0x20) ==0) sig=1;  // is input negative ?
   b0 &=0x1F;                   // discard bit 25..31
   ltw |= b0;
   ltw <<= 8;
   b0 = SPI_read();
   ltw |= b0;
   ltw <<= 8;
   b0 = SPI_read();
   ltw |= b0;
   ltw <<= 8;
   b0 = SPI_read();
   ltw |= b0;

   delayMicroseconds(1);

   sbi(PORTB,LTC_CS);           // LTC2400 CS Low
   delay(200);

   if (sig) ltw |= 0xf0000000;    // if input negative insert sign bit
   ltw=ltw/16;                    // scale result down , last 4 bits have no information
   volt = ltw * v_ref / 16777216; // max scale

   Serial.print(cnt++);
   Serial.print(";  ");
   printFloat(volt,6);           // print voltage as floating number
   Serial.println("  ");

 }
 sbi(PORTB,LTC_CS); // LTC2400 CS hi
 delay(20);

}
/********************************************************************/
byte SPI_read()
{
 SPDR = 0;
 while (!(SPSR & (1 << SPIF))) ; /* Wait for SPI shift out done */
 return SPDR;
}
/********************************************************************/
//  printFloat from  tim / Arduino: Playground
// printFloat prints out the float 'value' rounded to 'places' places
//after the decimal point
void printFloat(float value, int places) {
 // this is used to cast digits
 int digit;
 float tens = 0.1;
 int tenscount = 0;
 int i;
 float tempfloat = value;

 // if value is negative, set tempfloat to the abs value

   // make sure we round properly. this could use pow from
 //<math.h>, but doesn't seem worth the import
 // if this rounding step isn't here, the value  54.321 prints as

 // calculate rounding term d:   0.5/pow(10,places)
 float d = 0.5;
 if (value < 0)
   d *= -1.0;
 // divide by ten for each decimal place
 for (i = 0; i < places; i++)
   d/= 10.0;
 // this small addition, combined with truncation will round our

 tempfloat +=  d;

 if (value < 0)
   tempfloat *= -1.0;
 while ((tens * 10.0) <= tempfloat) {
   tens *= 10.0;
   tenscount += 1;
 }

 // write out the negative if needed
 if (value < 0)
   Serial.print('-');

 if (tenscount == 0)
   Serial.print(0, DEC);

 for (i=0; i< tenscount; i++) {
   digit = (int) (tempfloat/tens);
   Serial.print(digit, DEC);
   tempfloat = tempfloat - ((float)digit * tens);
   tens /= 10.0;
 }

 // if no places after decimal, stop now and return
 if (places <= 0)
   return;

 // otherwise, write the point and continue on
 Serial.print(',');

 for (i = 0; i < places; i++) {
   tempfloat *= 10.0;
   digit = (int) tempfloat;
   Serial.print(digit,DEC);
   // once written, subtract off that digit
   tempfloat = tempfloat - (float) digit;
 }
}

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.