We no longer sell products directly from the GHI Electronics website, click here for more details. Please find a Distributor to complete your online order. If you have any questions regarding this notice please contact us at support@ghielectronics.com.

Register Access

Last modified February 17, 2015

Table of Contents

Required

Tutorials: First NETMF Project

Introduction

To make the processor registers directly available to developers, We added the Register class.

Register PCONP = new Register(0xE01FC0C4);
// Enable timer2 and timer3
PCONP.SetBits((1 << 22) | (1 << 23));

Why 1 << 22 ?

It's easy to get the first bit (0x01), second bit (0x02) and so on but what about the higher bits such as 0x00400000? Which bit is this one? Instead of complicating things, let the compiler do the work for you. Simply use 1 << 22 for the 22nd bit.

Warning

This is an advanced feature

Pulse Counter

NETMF doesn't have a way to count pulses.

What if the processor supports it?

Here is an example that sets timer 3 and P0.4 on the LPC2478 processor to count pulses. While this code will compile on any platform, it will only work on LPC2478. Other processors have different registers and different features.

Files necessary to fully understand the example:

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

using GHI.Processor;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            Register PCONP = new Register(0xE01FC0C4);
            PCONP.SetBits(1 << 22);//enable timer2 

            // Select IO0 on EMX CAP2.0
            Register PINSEL0 = new Register(0xE002C000);
            PINSEL0.SetBits((3 << 8));//set bits 8 and 9

            // To enable timer/counter
            Register T2TCR = new Register(0xE0070004);
            T2TCR.Value = 1;

            // set prescale to 0
            Register T2PR = new Register(0xE007000C);
            T2PR.Value = 0;

            Register T2CTCR = new Register(0xE0070070);
            T2CTCR.Value = (2 << 0 | 0 << 2);//count on falling edge and use CAPn.0

            // should be 0 for a counter
            Register T2CCR = new Register(0xE0070028);
            T2CCR.ClearBits(0x07);

            // Don't do anything on match
            Register T2MCR = new Register(0xE0070014);
            T2MCR.Value = 0;

            // To reset the counter
            T2TCR.SetBits((1 << 1));
            T2TCR.ClearBits((1 << 1));

            // To read
            Register T2TC = new Register(0xE0070008);
            while (true)
            {
                uint count = T2TC.Value;

                Debug.Print("Total count: " + count);

                Thread.Sleep(1000);
            }
        }
    }
}
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.

* Indicates required fields.
This form is only for feedback not support.
Review our how to find information guide on locating helpful resources.