Main Site Documentation

CPU ticks


#1

I am coding a program to control a servo with a USB Joystick. So far so good, but I am having a problem where the FEZ randomly resets while running my code.

I think one of the issues may be that I am making too many calls to move the servo at a time, so I was going to put a debounce statement in to insure that I am only making X many calls to move the servo during Y seconds.

The problem is that I need a property or method to get the current amount of ticks from the last time the FEZ was restarted. Does such a method or property exist?

In case anyone is interested, here is my code

using System;
using Microsoft.SPOT;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.USBHost;
using System.IO;
using System.Threading;
using GHIElectronics.NETMF.FEZ;



namespace Servo
{
	public class Program
	{
		public static PWM servo = new PWM((PWM.Pin)FEZ_Pin.PWM.Di8);
		public static USBH_Joystick joystick;
		public static long 

		public static void Main()
		{
			servo.SetPulse(20 * 1000 * 1000, 1250 * 1000);
			Thread.Sleep(10000);
			servo.SetPulse(20 * 1000 * 1000, 1750 * 1000);
			Thread.Sleep(1500);

			USBHostController.DeviceConnectedEvent += joyConnected;
			Thread.Sleep(Timeout.Infinite);
		}

		public static long map(long x, long in_min, long in_max, long out_min, long out_max)
		{
			return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
		}

		public static void joyConnected(USBH_Device device)
		{
			if (device.TYPE == USBH_DeviceType.Joystick)
			{
				Debug.Print("Joystick connected...");

				joystick = new USBH_Joystick(device);

				joystick.JoystickXYMove += moveServo;
			}
		}

		public static void moveServo(USBH_Joystick sender, USBH_JoystickEventArgs args)
		{
			llong time = map(sender.Cursor.Y * -1, 0, 512, 1250, 1750);
			servo.SetPulse(20 * 1000 * 1000, (uint)time * 1000);
		}

	}
}

Yeah, I know it’s messy, but it should work.

EDIT: Actually, the FEZ my have been disconnecting because I was pulling too much current from the USB port. When I connected my AC adapter, the code functioned properly.


#2

Yes I was going to say something about power but you figured it out yourself :slight_smile:


#3

Yeah, it didn’t occur to me for a second.

The question still stand though, is there a way to get the number of ticks between now and the last reboot?


#4

Last reboot?! or Last boot?
I mean the time of how long the system has been on for or the time the system has been off!


#5

I just need some umber that goes up as a function of how long the board has been on for. I think DateTime.Now may be what I am looking for.


#6

Yes that is it