PIC Ramps

Morning

I was wondering if anyone had any pointers on Ramp generating on a PIC?

I have four channels that are on consecutively, they are provided from another PIC, I need to code a further PIC that will take these binary inputs and turn them into slow start/stop channels, the rise and fall being over about a second.

I'm looking at using the F505, once I have the ramps working I need the other 4 pins for an override function.

I was thinking of generating a single 10KHz heartrate then doing the work inside the periods of that. The idea being of having 10 periods in the second, the first with a 10% of the pulses high, then 20% then

30% etc sadlythis doesn't work that well because 60% is every x.xx pulses then 70% is only a fraction more, not whole pulses different. Does that make sense?!

Tom

Reply to
tom
Loading thread data ...

No, if you want to use the PWM function to control the output by hardware, then you must use the CCP1 or CCP2 pin that goes with that PWM unit. Of course you can always run a PWM in software and then you can use any general output pin you like. The disadvantage is that this takes up a lot of processor time, which you may not have to spare in your application.

I have a PWM application on a 12C671 that uses sofware and timers, but no PWM hardware. It was a real bugger to write. But now that it is written, it has been integrated into a standard product.

Robert Scott Ypsilanti, Michigan

Reply to
Robert Scott

Generating a PWM signal is easy.

Assume "P" is your desired output value, from 0 to 100%. Initialize S to 0.

At every 100 usec heartbeat do this:

if( (S += P) >= 100 ) { S -= 100; set_output() } else clear_output();

You can change P whenever you want to change the output value. To make a 1 second ramp, just increment/decrement P every 100 heartbeats. You don't even have to use a second timer.

As an optimization, you could use 128 or 256 instead of 100, and make use of assembly tricks to simplify things.

Reply to
Artenz

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.