Quantcast

Maximum PC

It is currently Tue Oct 21, 2014 10:59 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Control case lights with USB to parallel port converter
PostPosted: Mon Dec 07, 2009 11:36 am 
Willamette
Willamette

Joined: Mon Jan 07, 2008 2:35 pm
Posts: 1150
I'm thinking about doing a case mod over the Christmas break. I want to use the parallel port on the computer(easy to interface with, outputs are latched etc) to control a set of LED lights on the side of the case. I already have a schematic drawn for controlling the lights etc from the parallel port and i've done quite a bit of careful planning. I can get 5v power from the Molex or floppy connector.

My question here is simple: How badly can I mess up the motherboard (worst case scenario here) by shorting a couple of pins in the parallel port? Will it fry the entire motherboard? Could this issue be alleviated by using a USB to parallel port adapter or would that ruin the USB port if something went wrong?

$9 here is a cheap investment to keep from frying my motherboard...
http://www.newegg.com/Product/Product.a ... -_-Product


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 10, 2009 9:39 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
Some of what you are asking really depends on a few things.

Most LED projects that involve use of the parallel port rely on using pins 2 through 9 (Data 0 through Data 7). Since I can't see your drawing or what the plan is I can't really say if the adaptor will work in your case or not.

You mention getting 5 Volts so I'll venture a guess that you will have several LEDs and a resistor in series with each LED. The LED Cathode sides will connect to D0 through D7 of a parallel port and the LED Anodes will connect to 5 Volts. Driving any data port low will cause the LED to illuminate. All of this being a guess.

If you use a USB adapter this likely won't work if there is a software routine you have to communicate with the parallel port. The software would be looking for the parallel port (LPT1) and not a USB port to communicate. Another guess on my part.

Will shorting the parallel port pins fry a motherboard? Not likely.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 10, 2009 10:30 pm 
Willamette
Willamette

Joined: Mon Jan 07, 2008 2:35 pm
Posts: 1150
I was thinking of using a bread board and some integrated circuits (hence the need for a 5v power source) to experiment and see just how much I can do with a parallel port and some LED's.

I was thinking of just putting a resistor in series with each output pin from the parallel port to reduce the chance of actually shorting the parallel port.

I'm thinking about using some SR latches and maybe a decoder to give me the ability to control more than just 8 LED's. For now I just want to get the basic concept working and just control 8 LED's (one from each data pin) before I try to tackle anything too big.

I'm thinking of using C or C++ to interface with the parallel port, but i'm really not that familiar with C or C++. I'm wondering if Java would be a better choice as i'm much more fluent with Java (about 3 years of experience). I really don't care about speed as I do ease of use. (in my experience Java has been much easier to learn/program than C or C++).


Top
  Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 2:15 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
Actually you can do quite a bit with the parallel port. I would initially keep it simple using 8 lines (D0 through D7). There are other lines that could be addressed and used but you can do several cool things using just those 8 lines.

I would just work off the parallel port for the reasons I mentioned above. Not saying don't use a USB to Parallel converter but I think it would create problems.

Programming isn't my forte but I do some work in VB. We do have some very good programming types in here. They could likely help. Also I had a small program that may be good for openers. Let me see if I can find it. If I have some time at work today I'll post more. I can also give you some circuit buffer ideas to come off the port.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 5:09 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Uhm... I can't figure out what you are doing to need the parallel port. If you are going to build some big circuit just give it a 12 or 5v power source and call it a day.

I actually made a parallel LED board that had a linux C program to flash the LEDs at different frequencies. All you really need to do is wire up the + on the LEDs with an inline resistor to the D0-D7 data lines and ground the rest out. Easy peasy. I can take some pictures and if I can find the code I will see if I can post it (I didn't write it, so I need permission although I am nearly 110% positive he wrote it to be shared).

What do you hope to do. Saying "control some LEDs" is too vague for something like this.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 10:30 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
Quote:
We do have some very good programming types in here. They could likely help.


Wonder who I had in mind when I wrote that? Oh wait, that would have been Crash. Gee, look who found this thread. Just have to love coincidence. :)

Personally I wouldn't just do the straight LED thing and would likely buffer. However I think the parallel port can sink a little over 20 mA so I guess it would work fine. I know it can't source much but that matters not.

Crash, maybe just something basic to turn on D0 through D7. Maybe a binary clock feature, whatever, random?

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 6:43 pm 
Willamette
Willamette

Joined: Mon Jan 07, 2008 2:35 pm
Posts: 1150
I was just thinking that it would be neat to see what I could do with it. I was first planning on using maybe just 8 LED's to get a proof of concept and simply get the computer to sends 1's and zeroes to the parallel port to turn LED's on and off. Then maybe take it to the next level with some D-latches and a couple 2x4 decoders to try and control more than 8 lights at a time. At this point I really don't know how much I can really do with this, or how much I want to do with this.

Eventually I may want something to control some motors or (this is my friends idea) use some different circuit elements and some solid state relays to control christmas lights or something.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Dec 12, 2009 8:46 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
I am telling you that adding all those extra chips and logic isn't necessary. Where are you going to put the box at? That is a LOT of bulk for no reason.

It is really simple. And you can use the software to control when and how the LEDs engage. I have even seen these used for music applications, to sync with a media player on the computer to show the levels of the music.

Please forgive the less than stellar soldering job. This was the first thing I ever seriously soldered in my life. I have to find the C\C++ source code (keep in mind that it was written to be compiled as a kernel driver under Linux) but I know that I have it around somewhere. The blue wire is a ground. If you use a standard parallel cable and just hack of the ends you have the wires you need. I used a CAT5 cable so I had 8 wires for the LEDS but no ground wire.

Image Image Image


Top
  Profile  
 
 Post subject:
PostPosted: Sat Dec 12, 2009 8:55 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
teh 1337 haxxor wrote:
I was just thinking that it would be neat to see what I could do with it. I was first planning on using maybe just 8 LED's to get a proof of concept and simply get the computer to sends 1's and zeroes to the parallel port to turn LED's on and off.
See my post above...

Quote:
Then maybe take it to the next level with some D-latches and a couple 2x4 decoders to try and control more than 8 lights at a time. At this point I really don't know how much I can really do with this, or how much I want to do with this.
It will be much easier if you know exactly what you want to do with it. You can address as many as you like up to 256 LEDs ( 2^8 ) but you would be limited to changing the state of X leds per second based on the rate... which would probably be enough to change them all once per second or so.... actually I just did the math, you could change nearly all of them. 2 Mbps == 2000 bits per second. 8 bits per address/LED gives you 250 addresses per second. If you can get into some of the later standards you would be able to change 312 or so per second.

Quote:
Eventually I may want something to control some motors or (this is my friends idea) use some different circuit elements and some solid state relays to control christmas lights or something.
Again, you will want to know exactly what you are trying to accomplish. I am sure you could use the parallel port to trigger relays to turn lights on and off or whatever... but unless this is a for fun project there are already lots of products out there that do this.

Some good reading:
http://en.wikipedia.org/wiki/Parallel_port
http://en.wikipedia.org/wiki/IEEE_1284

A C# Example:
http://www.codeproject.com/KB/cs/csppleds.aspx


Last edited by CrashTECH on Mon Dec 14, 2009 7:57 am, edited 1 time in total.

Top
  Profile  
 
 Post subject:
PostPosted: Mon Dec 14, 2009 7:56 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
You'll also have to take in propagation delay depending on how deep you nest your TTL logic.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Dec 14, 2009 3:29 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
A few things to consider with this project. I managed a little time at work to see what would happen. Most newer machines do not afford a 5 Volt logic high on the parallel port. The typical logic high I saw was about 3.4 volts. The logic lows were about 50 mV which is fine. I would look to use the logic low to light the LEDs as according to the IBM specification you can sink more current than you can source. If you plan to drive other TTL Logic circuits I would buffer with some 2N2222 transistors or similar. If you need a cartoon (schematic) to work from I will be happy to provide one.

Something else to consider and Crash would be up on this much, much more than I am is the software to make things work. Microsoft Operating systems like Windows 98 allowed direct easy communication with the parallel port but to the best of my knowledge and I may be real wrong any Microsoft OS post Windows 98 using the NT (New Technology) does not allow a direct interface with the parallel port to do this. There is a need for a .dll file to be made. A popular .dll out there seems to be inpout.dll for getting things done. That creates a new problem as I don't know what will work beyond Windows XP. Linux is not a problem.

I have two machines I can develop and try things on and discovered that neither has a parallel port. Just wonderful. I do have an old parallel port card around here somewhere I could maybe try on my XP box.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Mon Dec 14, 2009 7:34 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Would pull up resistors work for getting the 3.4v to a logic high?
http://en.wikipedia.org/wiki/Pull-up_resistor

The article(s) I liked to talked about using that very DLL. Windows doesn't give you direct access to the hardware, which isn't such a bad thing IMO. Linux you can. I still have to dig up that source code....


Top
  Profile  
 
 Post subject:
PostPosted: Mon Dec 14, 2009 7:35 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
OP needs to come back and comment so we can further provide direction :)


Top
  Profile  
 
 Post subject:
PostPosted: Tue Dec 15, 2009 2:02 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
CrashTECH wrote:
OP needs to come back and comment so we can further provide direction :)


Yep as no sense in overdoing till we know if he wants to pursue it. Not sure about external pull up on a parallel port. I'll have to look into that maybe today.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Tue Dec 15, 2009 5:11 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Well, it is still fun to talk about anyway.

Why couldn't you use a pull-up? I mean if the range you want is 0 - 5v and the parallel data line only can output 3.4v (which is close to the low end of logic 1 anyway)? I guess it would also depend if you had the proper high voltage around to pull-up to.

I think I found that source code last night. I just need to get it posted.


Aside:
Wonder how hard it would be to provide a parallel port on a PCI card that you could also feed other logic into? Wonder how difficult it would be (hardware wise) to create a PCI compliant card to use internally as sort of a light controller?


Top
  Profile  
 
 Post subject:
PostPosted: Tue Dec 15, 2009 6:39 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Okay, found the code etc. First, the instructions, then the code file.

Keep in mind this was written up around the time Fedora Core 3 was hot and fresh! I can't really provide any support for the code as it is, one because I didn't write it and two I haven't developed any kernel drivers myself. I can help the best I can.

Quote:
1. Install correct version of Linux kernel source code if it is not already
installed. It's usually included as an option in the installation (Fedora Core 2 at least). Otherwise it is a separate package (RPM format, tgz format, etc.). Make sure it is the correct
kernel version. Check documentation if you are unsure how to do this (Fedora
Core 3 does not include kernel source in default installation).

[itexplorer@itexplorer itexplorer]$ uname --kernel-release
2.6.5-1.358

[itexplorer@itexplorer itexplorer]$ ls -l /usr/src
total 8
drwxr-xr-x 20 root root 4096 Mar 29 10:56 linux-2.6.5-1.358

2. Modify kernel Makefile for correct version. Usually the kernel "EXTRAVERSION"
includes a "custom" suffix to designate custom kernels. Here -1.358custom has
been replaced with -1.358

[root@itexplorer linux-2.6.5-1.358]# vi Makefile

VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 5
EXTRAVERSION = -1.358
NAME=Zonked Quokka

3. Copy the kernel configuration file from /boot to .config in the kernel
source directory. The version should match the kernel you are booting.

[root@itexplorer linux-2.6.5-1.358]#cp /boot/config-2.6.5-1.358 .config

3. Build Linux kernel headers and modpost script. Hit CONTROL-C after modpost
is built.

[root@itexplorer linux-2.6.5-1.358]#make oldconfig
[root@itexplorer linux-2.6.5-1.358]#make

4. Compile your module. If successful pulser.ko should be created.

[itexplorer@itexplorer pulser]$ make
make -C /usr/src/linux-2.6.5-1.358 SUBDIRS=`pwd` modules
make[1]: Entering directory `/usr/src/linux-2.6.5-1.358'
Building modules, stage 2.
MODPOST
make[1]: Leaving directory `/usr/src/linux-2.6.5-1.358'

5. Save everything. A buggy module can crash the kernel!

6. Install your module into the running kernel. If it fails check dmesg to see
why. Usually it there is a version problem based on differences between the
running kernel, the kernel configuration file, and the kernel Makefile.

[root@itexplorer pulser]# /sbin/insmod pulser.ko

[root@itexplorer pulser]# dmesg
Installing PULSER driver; assigned major number 253
manually mknod /dev/pulser c 253 0

7. Make your module's device file.

[root@itexplorer pulser]#mknod -m 0666 /dev/pulser c 253 0
[root@itexplorer pulser]# ls -l /dev/pulser
crw-rw-rw- 1 root root 253, 0 Mar 29 12:57 /dev/pulser

8. Test your module. Note that you don't have to be root user to write to
/dev/pulser because the permissions were generously set in mknod. If the LEDs don't flash check dmesg.

[root@itexplorer root]$ echo 1 4 8 10 20 4 2 1 > /dev/pulser
[root@itexplorer pulser]# dmesg
pulser_device_write (length 18 )
pulser frequency set to {1,4,8,10,20,4,2,1} Hz at count 0

9. Remove your module from the running kernel when you are done playing.

[root@itexplorer pulser]# /sbin/rmmod pulser.ko
[root@itexplorer pulser]# dmesg
Removing PULSER Driver after count 3530


CONGRATS! YOU ARE NOW A KERNEL HACKER..


Top
  Profile  
 
 Post subject:
PostPosted: Tue Dec 15, 2009 6:42 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Makefile
Code:
obj-m += pulser.o
# put this line in a Makefile that will be processed by "make modules" makefile
kit:
   make -C /usr/src/linux-`uname -r` SUBDIRS=`pwd` modules


pulser.c
Code:
/* pulser.c  20050328  JRB                */
/*           20050401  control all 8 bits */
/* adapted from lkmpg version 2.6         */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/fs.h>                                                       
#include <linux/workqueue.h>    /* schedule tasks    */
#include <linux/sched.h>        /* put self to sleep */
#include <linux/string.h>
#include <linux/interrupt.h>    /* for irqreturn_t   */
#include <linux/init.h>
#include <asm/io.h>             /* for inb, outb     */
#include <asm/uaccess.h>        /* for put_user      */

#define pulser_DEVICE_NAME "pulser"     
#define pulser_NODE_NAME   "/dev/pulser"  /* Dev name as it appears in /dev    */
#define pulser_WORKQUEUE   "WQpulser.c"   /* name will appear in process table */

MODULE_LICENSE("GPL");
MODULE_AUTHOR("John Bork");
MODULE_DESCRIPTION("Parallel Port Output Pulser");
MODULE_SUPPORTED_DEVICE(pulser_DEVICE_NAME);

/* function prototypes */
static int           pulser_device_open(struct inode *, struct file *);                 
static int           pulser_device_release(struct inode *, struct file *);
static ssize_t       pulser_device_read(struct file *, char *, size_t, loff_t *);
static ssize_t       pulser_device_write(struct file *, const char *, size_t, loff_t *);
static void          pulser_process_io(void *);

/* module global variables */
static struct file_operations pulser_fops = {
   .read    = pulser_device_read,
   .write   = pulser_device_write,
   .open    = pulser_device_open,
   .release = pulser_device_release
};

static struct workqueue_struct * pulser_workqueue;
static struct work_struct pulser_task;
static        DECLARE_WORK(pulser_task, pulser_process_io, NULL); /* what function to execute for workqueue */

/* kernel-defined module and non-user-controllable parameters */
static int    pulser_base_port       =  0x378; /* standard address of LPT1 (parallel port)    */
static int    pulser_major;                    /* Major number assigned to our device driver  */
static int    pulser_output_counter  =  0;     /* How many pulses since module installed      */
static int    pulser_workqueue_delay =  5;     /* How often I/O process occurs (milliseconds) */

/* run time configuration and system state                                  */
/*  initially OFF (not pulsing parallel port outputs)                       */
/*  need period (frequency) and pulse duration for normal, cyclic operation */
/*  e.g., 30Hz 10% duty cycle                                               */
static unsigned int pulser_duty_cycle      = 10; /* Percentage of process cycle period HIGH pulse occurs */
/* frequency will be converted to millisecond countdown timers   */
static unsigned int pulser_frequency[8]    = {30, 0, 0, 0, 0, 0, 0, 0};
static int          pulser_open            =  0; /* Is device open? (initially closed)                   */

static int __init pulser_init(void)
{
   char status;

   /* register character major device number */
   pulser_major = register_chrdev(0, pulser_DEVICE_NAME, &pulser_fops);
   if (pulser_major < 0)
   {
      printk(KERN_INFO "Registering the character device failed with %d\n", pulser_major);
      return pulser_major;
   }
   printk(KERN_INFO "Installing PULSER driver; assigned major number %d\n", pulser_major);

   /* remind of need to make node if non-existent */
   /* e.g., mknod -m 0666 /dev/pulser c 254 0     */
   printk(KERN_INFO " manually mknod -m 0666 %s c %d 0\n", pulser_NODE_NAME, pulser_major);

   /* set direction of data port to output */
   status = inb(pulser_base_port + 2);
   status = status & ~0x20;
   outb(status, pulser_base_port + 2);

   /* create but do not start workqueue (initially starts with first write) */
   pulser_workqueue = create_workqueue(pulser_WORKQUEUE);

   return 0;
}

static void __exit pulser_cleanup(void)
{
   int stat;
   printk(KERN_INFO "Removing PULSER Driver after count %d\n", pulser_output_counter/2);
   stat = unregister_chrdev(pulser_major, pulser_DEVICE_NAME);
   if (stat < 0)
      printk(KERN_INFO "Error in unregister_chrdev: %d\n", stat);
   cancel_delayed_work(&pulser_task);
   flush_workqueue(pulser_workqueue);
   /* necesary operations to prevent kernel crash */
   destroy_workqueue(pulser_workqueue);
   /* (from LKMPG)
    * Sleep until intrpt_routine is called one last time. This is
    * necessary, because otherwise we'll deallocate the memory holding
    * intrpt_routine and Task while work_timer still references them.
    * Notice that here we don't allow signals to interrupt us.
    *
    * Since WaitQ is now not NULL, this automatically tells the interrupt
    * routine it's time to die.
    */
}

module_init(pulser_init);
module_exit(pulser_cleanup);

static int pulser_device_open(struct inode *inode, struct file *file)
{
   /* allow only one open instance at a time */
   /* will be called at beginning of user read or write character device file (/dev/pulser) */
   if (pulser_open)
      return -EBUSY;
   pulser_open++;
   /* increment module usage counter */
   try_module_get(THIS_MODULE);
   return 0;
}

static int pulser_device_release(struct inode *inode, struct file *file)
{
   /* will be called whenever at beginning of user read or write character device file (/dev/pulser) */
   pulser_open--;
   /* decrement usage counter */
   module_put(THIS_MODULE);
   return 0;
}

static ssize_t pulser_device_read(struct file *filp, char *buf, size_t len, loff_t * offset)
{
   /* send data from kernel space to user space (can be via character device file) */
   /* initially do nothing; later return information about current state           */
   int bytes_read=0;
   printk(KERN_INFO " pulser_device_read\n");
   return bytes_read;
}

static ssize_t pulser_device_write(struct file *filp, const char *buf, size_t len, loff_t * offset)
{
   char databuf[25];
   char * ptr = databuf;
   int bytes_written = 0;
   unsigned int i,j;

   /* what are you going to get from user-space?              */
   /* ASCII representations of frequency and duty cycle       */
   /* 20050401 allow specification for frequency for each bit */
   for(bytes_written=0; bytes_written<sizeof(databuf) && len; len--, bytes_written++)
      get_user(*(ptr++), buf++);
   printk(KERN_INFO " pulser_device_write (length %d)\n", bytes_written);

   /* return error if still bytes to write */
   if(len)
      return -1;

   /* initially only accept one or two characters for frequency */
   for(ptr=databuf, i=0; i<8 && ptr-databuf < bytes_written-1; i++, ptr++)
   {
      if(ptr-databuf >= bytes_written-3)
      {
         if(ptr-databuf == bytes_written-2)
            pulser_frequency[i] = *ptr - '0';
         else
         {
            pulser_frequency[i] = (*ptr - '0') * 10 +(*(ptr+1) - '0');
            ptr++;
         }
      }
      else
      {
         if(*(ptr+1) == ' ')
            pulser_frequency[i] = *ptr - '0';
         else
         {
            pulser_frequency[i] = (*ptr - '0') * 10 +(*(ptr+1) - '0');
            ptr++;
         }
         ptr++;
      }
      if(pulser_frequency[i] > 60)
         return -1;
   }
   /* set the remainder bits to zero Hz*/
   for(j=i; j<8; j++)
      pulser_frequency[j] = 0;

   for(j=0; j<8; j++)
      if(pulser_frequency[j])
         break;
   if(j == 8)
   {
      /* write zeros to all bits of output         */
      outb(0, pulser_base_port);
   }
   else
   {
      /* initially act on command to start process */
      queue_delayed_work(pulser_workqueue, &pulser_task, pulser_workqueue_delay);
   }

   printk(KERN_INFO "pulser frequency set to {%d,%d,%d,%d,%d,%d,%d,%d} Hz at count %d\n",
                    pulser_frequency[0], pulser_frequency[1],pulser_frequency[2],pulser_frequency[3],
                    pulser_frequency[4], pulser_frequency[5],pulser_frequency[6],pulser_frequency[7],
                    pulser_output_counter/2);
   return bytes_written;
}

static void pulser_process_io(void * dummy)
{
   static char last_output    = 0; /* for resource conservation strategy          */
   static char output_byte    = 0; /* byte that will be written to parallel port  */
   static int pulser_timer[8] = {0,0,0,0,0,0,0,0}; /* main process countdown timer                */
   static int pulse_timer[8]  = {0,0,0,0,0,0,0,0}; /* countdown for HIGH part of pulse            */
   int i;
   /* output parallel port bit(s) based on counter(s)                          */
   /*  need period (frequency) and pulse duration for normal, cyclic operation */
   /*  e.g., 30Hz 10% duty cycle yields                                        */
   for(i=output_byte=0; i<8; i++)
   {
      if(pulser_frequency[i])
      {
         if(!pulser_timer[i])
         {
            /* start a new cycle with HIGH pulse */
            pulser_timer[i] = 1000 / pulser_frequency[i];
            /* useless to use pulse_timer if duty cycle >= 100% */
            pulse_timer[i]  = 10 * pulser_duty_cycle / pulser_frequency[i];
            /* output bit set HIGH */
            output_byte  |= (1<<i);
         }
         else
         {
            if(pulser_duty_cycle < 100)
            {
               /* decrement pulse timer */
               if(pulse_timer[i] - pulser_workqueue_delay > 0)
               {
                  pulse_timer[i] -= pulser_workqueue_delay;
                  output_byte  |= (1<<i);
               }
               else
               {
                  pulse_timer[i] = 0;
                  /* output bit set LOW */
                  output_byte &= ~(1<<i);
               }
            }
            else
               output_byte  |= (1<<i);
         }
      }
      /* decrement pulser timer */
      if(pulser_timer[i] - pulser_workqueue_delay > 0)
         pulser_timer[i] -= pulser_workqueue_delay;
      else
         pulser_timer[i] = 0;
   }
   /* output byte to parallel port (save resources by only outputting change) */
   if(output_byte != last_output)
   {
      outb(output_byte, pulser_base_port);
      last_output = output_byte;
      pulser_output_counter++;
   }

   /* reschedule this task for re-execution after the workqueue_delay timer interrupts */
   for(i=0; i<8; i++)
      if(pulser_frequency[i])
         break;
   if(i != 8)
      queue_delayed_work(pulser_workqueue, &pulser_task, pulser_workqueue_delay);
}


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 16, 2009 3:46 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
CrashTECH wrote:
Well, it is still fun to talk about anyway.

Why couldn't you use a pull-up? I mean if the range you want is 0 - 5v and the parallel data line only can output 3.4v (which is close to the low end of logic 1 anyway)? I guess it would also depend if you had the proper high voltage around to pull-up to.

I think I found that source code last night. I just need to get it posted.


Aside:
Wonder how hard it would be to provide a parallel port on a PCI card that you could also feed other logic into? Wonder how difficult it would be (hardware wise) to create a PCI compliant card to use internally as sort of a light controller?


I guess a pull-up could be played around with if the plan was to just drive 8 LEDs from a parallel port. My reads on today's parallel ports is they seem to vary as to output.

If I were to consider what teh 1337 haxxor mentions I would likely try shoving an octo buffer chip in there right off the port and get everything nice and TTL happy. That would afford 8 data lines to do with as the user chooses. I guess much of the electronics circuitry really depends on what you want to do.

As to PCI cards with IO there are dozens of them out there by companies like HP and NI. I have used several cards like this for data acquisition and control. Then they also may have analog in and out channels as well. I really like the newer USB boxes for stuff like this as there are some nice boxes out there.

Back close to topic, most of these Christmas displays work off ports. Simple systems run off a parallel port while the more elaborate systems use the serial RS232 port. There is no limit to some of that stuff.

Man Crash you posted a mountain of code. I have to see what I can find that runs on just a parallel port, under Windows, to control the Data Lines out.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 16, 2009 4:49 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
I found something that looks pretty cool and promising. Check this out.

They sell a relay board controlled from the parallel port but if you look on the linked web page they have the software for download as well as a pdf with a complete schematic of the card. Good material there.

My problem is the only damn XP machine I have is my workstation and I used the PCI Parallel Port card I finally found. It wants to be LPT3 and I don't think my software is seeing it at this point. Maybe I can screw with it. My only other option is to try it on my old test box which currently has Windows 7 both 32 & 64 bit on it so I'll likely need to reinstall XP which is in the future anyway. I doubt the stuff will run on Windows 7. It likely may not run on Vista which is my everyday machine in 64 bit.

Anyway it is a start. I did see another program done in VB and need to find it again as they gave the source code.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 16, 2009 6:12 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Reloadron wrote:
Man Crash you posted a mountain of code. I have to see what I can find that runs on just a parallel port, under Windows, to control the Data Lines out.
Check out the code project link that I have a few posts back. C# project I believe.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.