Re: Period Wave Modulation

"Wayne E. Van Loon Sr." <[email protected]> Wed, 02 Feb 2005 21:49:40 -0800
Newsgroups gmane.linux.real-time.rtlinux.general
Message-ID <[email protected]>

Jesse Vogt wrote:
> Hello,
> 
> I am using RTLinux and a CIO-DIO48H digital I/O board to control
> several servo motors. I need to create a 10 kHz  wave with a variable
> duty cycle.  I am able to generate a solid 10 kHz wave using periodic
> thread but that only allows a 50% duty cycle.  Any ideas?

Change the periodic rate every interrupt.

If your rtl application always needs to be able to respond to other 
events such as hardware interrupts, then I would do something like the 
following:

ghrtime = gethrtime();

(calculate next_transition_time)

pthread_make_periodic_np( pthread_self(), ghrtime,
   		  next_transition_time - ghrtime  );
pthread_wait_np();

(flip a bit)

This changes the period of the process but doesn't suspend it. This way 
your rtl process can still respond to interrupts.

The CPU is surrendered at the pthread_wait_np(), so it doesn't waste CPU 
cycles. Your task will resume at next_transition_time, at which time, 
you flip your PWM bit and start the whole cycle over again.

Wayne
> 
> Thanks,
> 
> Jesse
> _______________________________________________
> Rtl mailing list
> [email protected]
> http://www2.fsmlabs.com/mailman/listinfo/rtl
> 

_______________________________________________
Rtl mailing list
[email protected]
http://www2.fsmlabs.com/mailman/listinfo/rtl