ts-7000
[Top] [All Lists]

Re: [ts-7000] Re: TS-XDIO sample code.

To:
Subject: Re: [ts-7000] Re: TS-XDIO sample code.
From: "Don W. Carr" <>
Date: Mon, 17 Apr 2006 16:07:32 -0500
Well, I could see the attachment on my end, maybe because I sent it. I suppose they might strip the the attachments off at yahoo. Anyway, here is the code pasted directly as text. Don.

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>


/******************************************************************/

static unsigned char *xdio_start;
static unsigned char *xdio_r0;
static unsigned char *xdio_r1;
static unsigned char *xdio_r2;
static unsigned char *xdio_r3;
static unsigned short *ptr16;

#define TV_ELAPSED_US(x, y)     ((((x).tv_sec - (y).tv_sec) * 1000000) + \
        ((x).tv_usec - (y).tv_usec))

/*********************************************************************/

long calc_dif(long count, long last)
{
  if (last > count)
  {
    // Ok, we rolled over
    return count + 65536 - last;
  }
  else
  {
    return count - last;
  }
}

/*********************************************************************/

int main(int argc, char *argv[])
{
  int fd = open("/dev/mem", O_RDWR|O_SYNC);
  //xdio at 0x12c00000-0x12c00003
  xdio_start = (unsigned char *) mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x12C00000);
  xdio_r0 = (unsigned char *) (xdio_start + 0);
  xdio_r1 = (unsigned char *) (xdio_start + 1);
  xdio_r2 = (unsigned char *) (xdio_start + 2);
  xdio_r3 = (unsigned char *) (xdio_start + 3);

  ptr16 = (unsigned short *) xdio_r2;

  *xdio_r0 = 0x40; // ?? give me the value to write here
  *xdio_r1 = 0x00; // ?? give me the value to write here
/***
  *xdio_r0 = 0x82;
  *xdio_r1 = 0x00;
   for discrete outputs
  *xdio_r0 = 0x00;
  *xdio_r1 = 0xFF;
****/

  printf("Wrote, r0 = 0x43, r1 = 0x00\n");

  struct timeval now;
  struct timeval last_time;
  gettimeofday(&last_time, NULL);
  unsigned short last_count = *ptr16;
  while (1)
  {
    sleep(1);
    gettimeofday(&now, NULL);
    unsigned short count16 = *ptr16;
    int elapsed_time = TV_ELAPSED_US(now, last_time);
    long n_pulses = calc_dif((long) count16, (long) last_count);
    double frequency = ((double) n_pulses) / (((double) elapsed_time) / 1000000);
    unsigned char byte0 = *xdio_r2;
    unsigned char byte1 = *xdio_r3;
    printf("--- %02hhx %02hhx %02hhx %02hhx -  %hx %hu  %d %d %0.0lf\n",
         xdio_r0, *xdio_r1, byte0, byte1, count16, count16, n_pulses, elapsed_time, frequency);

    last_count = count16;
    last_time = now;
  }
}

/******************************************************************/



On 4/17/06, rx7vt <> wrote:
--- In "Don W. Carr" <> wrote:
>
> I wrote some code, and it appears to work, but with glitches, such
that some
> times, the new count I read is actually less than the previous
count, and,
> it appears to not count all pulses. I had an external source set to
EXACTLY
> 100 Hz, and expected to get 200 Hz since the xdio counter counts both
> falling and rising edges, but got consistantly lower.

Looks like attachments don't work. Could you upload the file to the
'files' section? (Or, if I'm missing something about how to see the
code that you sent, please enlighten me....)

Thanks...








SPONSORED LINKS
Linux os Hardware Arms
Computer internet Computer security Computer hardware security


YAHOO! GROUPS LINKS

  •  Visit your group "ts-7000" on the web.
     
  •  To unsubscribe from this group, send an email to:
     =Unsubscribe
     
  •  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.





--
Dr. Don W. Carr
J. G. Montenegro 2258
Guadalajara, Mexico
+52-333-630-0704
+52-333-836-4500 ext 2930


YAHOO! GROUPS LINKS

  •  Visit your group "ts-7000" on the web.
     
  •  To unsubscribe from this group, send an email to:
     =Unsubscribe
     
  •  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU