>-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] >Sent: 04 January 2006 13:33 >To: Microcontroller discussion list - Public. >Subject: Am I crazy? PWM on a 12f629 > > >Hi, >I'm the software developer for a little company called >Corvette Engineering. I'm a C++ /windows / Unix programmer by >trade, though I did do some 68HC11 development back in the >latter part of last century. Boy it's cramped in these PIC devices! > >OK, pretty new to the PIC world, so I'm wondering if the above >pic is going to make me suffer in the following >application...or if I should get a fancier PIC with a built in >PWM or even one O them thar motor controller PICs? I like the >8 pin package... > > >This is an extremely simple project, The goal is to measure >the frequency of the input signal and use it to vary the PWM >which will drive a FET that controlls a 12v solenoid. > >I have a PWM running using timer0, so that wasn't too bad. > >I plan on using interrupts on a GPIO pin to measure the period >of the incomming signal. > > >Outputs > 250hz PWM > >Inputs > 0 to ~5khz TTL square wave signal > 2 push buttons, used to modify the PWM vs frequency slope, >min and max. > >some simple math to compute the current frequency and set the >current PWM duty cycle. > >So >Crazy or not? Not crazy at all, quite doable. The 16F629 has two counters, so you can set up the other one (timer1) in counter mode to make the incomming pulses increment the timer. If you check the number of pulses counted within a fixed period, then you have frequency. Your PWM timer is running at a fixed rate, so you can check the value in timer1 at a suitable multiple of this period, after which you would either clear the timer1 registers ready for the next measurement, or just store the current value to subtract from the next value. This means all output and input capture will be handled via interrupts. You main loop can then handle the button polling and slope adjustment etc. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist