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.

Sinan

Member Since 12 Oct 2011
Offline Last Active Apr 14 2013 06:13 PM
-----

Topics I've Started

PWM freezing due to PWMChannels mapping

11 April 2013 - 10:05 AM

I am trying to work with PWM but failed to access the onboard led. None of the examples found on the forum will function as expected.

 

The simple example below crashes on a Netduino1 with the 4.2.01 framework.

 

[font="'courier new', courier, monospace;"]using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication1
{
  public class Program
  {
  public static void Main()
  {
  PWM pwm = new PWM(PWMChannels.PWM_ONBOARD_LED, 100, 0.5, false);
  pwm.Start();
  Thread.Sleep(Timeout.Infinite);
  }
  }
}[/font]

 

 

As soon as it hits the pwm initialization, the board freezes. After many variations of this code and too many erase&reboot sessions, I have checked the enumeration of the available PWMChannels.

 

[font="'courier new', courier, monospace;"]   Debug.Print("None: " + PWMChannels.PWM_NONE.ToString());
  Debug.Print("LED: " + PWMChannels.PWM_ONBOARD_LED.ToString());
  Debug.Print("Pin 3: " + PWMChannels.PWM_PIN_D3.ToString());
  Debug.Print("Pin 5: " + PWMChannels.PWM_PIN_D5.ToString());
  Debug.Print("Pin 6: " + PWMChannels.PWM_PIN_D6.ToString());
  Debug.Print("Pin 9: " + PWMChannels.PWM_PIN_D9.ToString());
  Debug.Print("Pin 10: " + PWMChannels.PWM_PIN_D10.ToString());
  Debug.Print("Pin 11: " + PWMChannels.PWM_PIN_D11.ToString());[/font]

 

Rather disturbing debug.print results:

[font="'courier new', courier, monospace;"]None: -1
LED: -1
Pin 3: -1
Pin 5: 0
Pin 6: 1
Pin 9: 2
Pin 10: 3
Pin 11: -1[/font]
 

 

Same code for PWM_Pin_D6 works as expected (checked with a logic analyzer).

 

Is the code freezing due to the missing mappings for these pins? And, can I do something to access the onboard led and the pins 3 and 11?

 

Regards, Sinan


I2C problem by MS5611 sensor

18 May 2012 - 12:15 AM

Hi everyone,

I am trying to build a variometer using the Mod-1009 board for MS5611-01BA barometric pressure sensor from Embedded Adventures.

Unfortunately, I cannot read values from the i2c port. SDA is connected to Analog 4, SCLK to 5 and the VCC to 3.3v. I am using the latest framework (4.2).

I am OK with C# and .net but I am clueless in this world. Bellow is my code where the device.Execute always returns zero in the ReadFromDevice method.

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace MS5611baro
{
  // Mod-1009 board for MS5611-01BA Barometric Pressure Sensor from
  // Embedded Adventures (http://www.embeddedadventures.com/barometric_pressure_sensor_module_mod-1009.html) 
  // MS5611 datasheet http://www.embeddedadventures.com/datasheets/ms5611.pdf
  // Mod-1009 description http://www.embeddedadventures.com/datasheets/MOD-1009_hw_v1.pdf
  // 
  // VCC  --> 3.3v
  // SDA  --> Analog 4
  // SCLK --> Analog 5
  // 
  // Pull up resistors: (from Mod-1009 description) The board comes with the pull-up resistors enabled. If you are
  //   connecting to an existing I2C buss that already has pull-up resistors, or you are using internal pull-ups in 
  //   your microcontroller, you can disable the pull-up resistors by cutting the PCB jumpers on the MOD-1009 board. 
  public class MS5611_MOD1009
  {
    private const byte _cmdReset = 0x1E;
    private const byte _cmdPromReadBase = 0xa0;
   
    private const ushort _i2cAddr = 0x76; //Embedded Adventures module CSB is VCC --> HIGH --> 0x76

    public UInt16[] CalibrationArray = new UInt16[6];
    public int LastTransactionCount = -1;

    private I2CDevice _device = new I2CDevice(new I2CDevice.Configuration(_i2cAddr, 10));

    /// <summary> Mod-1009 board for MS5611-01BA Barometric Pressure Sensor from Embedded Adventures</summary>
    public MS5611_MOD1009()
    {
      while (LastTransactionCount < 1)
      {
        WriteToDevice(_cmdReset, 100); // ResetSensor();       
      }
    }

    public bool WriteToDevice(byte command, int timeOut = 5)
    {
      I2CDevice.I2CWriteTransaction wt = I2CDevice.CreateWriteTransaction(new byte[] { command });
      LastTransactionCount = this._device.Execute(new I2CDevice.I2CTransaction[] { wt }, 3);
      return LastTransactionCount > 0;
    }

    public bool ReadFromDevice(byte[] readBuf, int timeOut = 100)
    {
      var rtArr = new I2CDevice.I2CReadTransaction[] { I2CDevice.CreateReadTransaction(readBuf) };
      LastTransactionCount = _device.Execute(rtArr, timeOut);  // --> returns allways zero
      return LastTransactionCount == readBuf.Length;
    }

    public void ReadCalibrationData()
    {
      for (byte i = 0; i < 6; i++)
      {
        CalibrationArray[i] = ReadSingleCalibrationValue((byte)(i + 1));
      }
    }

    private UInt16 ReadSingleCalibrationValue(byte valueToRead)
    {
      //  1 0 1 0 X X X 0  - The XXX part is used for the parameter index
      byte paramIndex = (byte)(_cmdPromReadBase + (valueToRead << 1));
      // This sets up the system into PROM read mode.
      if (WriteToDevice(paramIndex))       // --> returns true
      {
        byte[] readBuf = new byte[2];
        // This part gets the data from the system.
        if (ReadFromDevice(readBuf, 100)) // --> returns allways false, readBuf is empty {0, 0}
        {
          return (UInt16)(readBuf[0] << 8 | readBuf[1]);
        }
      }
      return 0;
    }
  }
}


using System;
using System.Threading;
using Microsoft.SPOT;

namespace MS5611baro
{
  public class Program
  {
    public static void Main()
    {
      var baro = new MS5611_MOD1009();
      baro.ReadCalibrationData();
    }
  }
}


Thanks for help,
Sinan

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.