Searching \ for '[PIC] Am I crazy? PWM on a 12f629' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/ios.htm?key=pwm
Search entire site for: 'Am I crazy? PWM on a 12f629'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Am I crazy? PWM on a 12f629'
2006\01\04@135253 by Keith

flavicon
face

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?

Thanks
Keith

2006\01\04@150136 by olin piclist

face picon face
Keith wrote:
> 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!

It takes a different mindset to program small resource-limited systems.
It's not for everyone.

> 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...

It depends you your tradeoffs.  If this is a high volume product then you're
probably going down the right path.  If not, then development cost will
outweight the saving so of a buck or two per PIC.  You'll probably find it
easier to use a PIC with more hardware support, like PWM.  However if you
really need it to be only 8 pins then I don't think you get PWM hardware.

{Quote hidden}

I think this is doable but I wouldn't promise it without some investigation
due to the 5KHz input frequency.  I'm a bit uncomfortable with multiple
interrupts going on possibly messing up the PWM, at least until I can
analyse it further and decide it's not an issue.

This part has an internal 4MHz oscillator, so your instruction rate will be
1MHz.  At 250Hz PWM you have 4000 instructions per PWM period.  Let's say
you make your PWM slice time 100 instructions, that gets you 41 different
output values.  That's probably enough to control your solenoid, but you
need to be sure.

I haven't looked at this in detail so this is just a knee jerk reaction, but
I would look into using timer 1 to accumulate input pulses and check the
value at regular intervals instead of trying to capture individual input
pulses at 5KHz.  You're going to have a fairly fast regular interrupt for
the PWM anyway, and I would look into having this do the frequency
measurement also.

Now that I'm thinking about this more, it sounds more doable but I think is
not a trivial or beginner project.  If this is for a real commercial
application, it may be more cost effective to have some like me who does
this for a living take care of the PIC part.


******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

2006\01\04@151741 by Wouter van Ooijen

face picon face
> Outputs 250hz PWM

250hz PWM is very easy in software, no trouble at all.

> So
> Crazy or not?

If it's for a one-of I'd select a big chip anyway, probably an 18F4520.
But if you want 8 pin and PWM: 12F683.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu


2006\01\04@154646 by Bill Freeman

flavicon
face
Olin Lathrop writes:
>   ...  However if you
> really need it to be only 8 pins then I don't think you get PWM hardware.

       12F683 has PWM.

2006\01\04@164514 by Jan-Erik Soderholm

face picon face
Hi !

Others have already pointed out that the 12F683
*has* an hardware PWM unit. I'd just like to add that
it (compared to the one you are using now) also have
double the program mem (2Kword), double the RAM
(64 bytes) and also the new and much better INTOSC.
Still in the same 8-pin size.

It's it's reasonable low-volume, you'd probably save
some development time by using that one instead.

Regards,
Jan-Erik.



2006\01\05@113558 by Keith

flavicon
face
Thanks everyone. I find the pic very interesting, I'm starting to like it.
I think I did go off the deep end on the price of the processor issue, I
mean if I double the price I'm still at less than $2, that's not a lot of
programming time! This isn't that cost sensitive of a project that a $5
processor would kill it.

Time to look at the better and faster processors. I'm sure the 12F629 could
be optimized to do it but it would be a real squeeze. The 12F683, does look
a lot better and I could run it at 20 Mhz Hmmm, that would be a lot better
to capture that 5k input frequency...

BTW, Microchip does not list PWM capabilities for the 12F683, is the
website wrong?



{Original Message removed}

2006\01\05@123029 by olin piclist

face picon face
Keith wrote:
> The 12F683, does look a lot better and I could run it at 20 Mhz

Yes, but then you need an external oscillator which will eat a pin or two.
The 12F683 does have a 8MHz internal oscillator as apposed to the 4MHz of
the 12F629, so you get 2x right there.  Also since you can use a hardware
PWM generator the PWM resolution and speed can be a lot higher at the same
clock rate.

> Hmmm, that would be a lot better to capture that 5k input frequency...

You might still be better off capturing pulses over fixed time periods, then
low pass filtering a bit to reduce jitter.  How fast does the output need to
be updated?

> BTW, Microchip does not list PWM capabilities for the 12F683, is the
> website wrong?

If in doubt, always check the data sheet.  I just looked in the
January-March 2006 line card (now known as Selector Guide) and it shows the
12F683 as having a CCP module.


******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

2006\01\06@054911 by Michael Rigby-Jones

picon face


{Quote hidden}

I guess you didn't get the reply I sent to your first (untagged) post, so I'll re-post it.


> 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.
=======================================================================

2006\01\06@065722 by Bill & Pookie

picon face
If this is for a learning expierence, and one 12f629 is good, why not use
two pic's.  One for input stuff and the other for output?

Bill

{Original Message removed}

2006\01\06@093014 by Keith

flavicon
face
Thanks for reposting Mike, that is a brilliant idea! The frequency
measurement overhead should be almost zero. And input frequency well above 5
khz :-D

I'm liking the 629 again


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...