Searching \ for '[PIC]: percentage time reglage' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=time
Search entire site for: 'percentage time reglage'.

Exact match. Not showing close matches.
'[PIC]: percentage time reglage'
2002\04\01@061139 by

Hi again piclisters !

I have a problem here: I'm trying to understand a methode for switching
on and off one pic output respecting an input percentage proportion from
10% to 90% of a pre-programmed time value ( from 10 seconds to 10 minutes
). With other words:
10% from 10 seconds means 1 second on + 9 seconds off
10% from 10 minutes means 60 x ( 1 second on + 9 secons off)
...
90% from 5 minutes and 30 seconds means 33 x (9 seconds on + 1
second off)

How I can define a common algorithm which fits on any time and any
percentage ?

Vasile

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

On Mon, 1 Apr 2002 14:11:20 +0300, Vasile Surducan wrote:

>Hi again piclisters !
>
>I have a problem here: I'm trying to understand a methode for switching
>on and off one pic output respecting an input percentage proportion from
>10% to 90% of a pre-programmed time value ( from 10 seconds to 10 minutes
>). With other words:
>10% from 10 seconds means 1 second on + 9 seconds off
>10% from 10 minutes means 60 x ( 1 second on + 9 secons off)
>...

But 10% from 600 seconds means 60 seconds on and 540 seconds off. :=)

Unless there's some reason not to do it, your math will be a little
more straightforward if you can do everything in seconds rather than
mixing units.

Regards, Bob

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

> I have a problem here: I'm trying to understand a methode for switching
> on and off one pic output respecting an input percentage proportion from
> 10% to 90% of a pre-programmed time value ( from 10 seconds to 10 minutes
> ). With other words:
> 10% from 10 seconds means 1 second on + 9 seconds off
> 10% from 10 minutes means 60 x ( 1 second on + 9 secons off)
> ...
> 90% from 5 minutes and 30 seconds means 33 x (9 seconds on + 1
> second off)
>
> How I can define a common algorithm which fits on any time and any
> percentage ?

This sounds simple if you rephrase it as a PWM output lasting for a
specified time.  Since your PWM period is 10 seconds, this is simple to do
in software.  If 10% resolution is enough, then you only need an interrupt
every second to re-evaluate the PWM output.

I think you already know this, Vasile, so what am missing?

*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

> How I can define a common algorithm which fits on any time
> and any percentage ?

Hi Vasile, I'm looking at something very similar today. A PWM
output that varies from 1:254 to 254:1 over an adjustable time-
base. ie using a TMR0 interrupt it could be as short as few
instruction cycles per "on" bit as possible right up to several
milliseconds per "on" bit, all the time keeping the same ratio
of off:on. IOW, the PWM can be altered as well as the overall
frequency. Mine is a little more complicated than yours in that
I want to have a "fine" and "coarse" adjustment (via pots)

But enough about me - I'll be interested in any algorithms
you find that might be applicable to what I'm doing. Could I
suggest that you look at the two parameters separately -
on:off ratio and "magnification" ratio. Determine a base
unit of measurement, perhaps a timer interrupt, and use
a RAM counter as the amount to scale the on:off times.

There's a list of maths routines here

http://www.piclist.com/techref/microchip/math/basic.htm

I know % calculations have been discussed on the list. IIRC
do your multiplication first, then the division (to minimise
errors). In your case, perhaps not think in terms of percentages
but "per hectamillages" ?? ie use 10,000-base (16-bit) rather
than 100-base (8-bit). You would get finer resolution and
smaller errors

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

Thanks all guys ( Bob, Olin and Joe in mail receiving order )
As usual, language bariers have stopped me to put the right question.

Bob, I need a finest resolution so every time the minimum period will be
10 seconds and no more, for 10 minutes and 10% I need to do 60 times 1
second on and 9 secons off.

Olin and Joe, I'm using an internal RTC ( interrupt tmr0 based ) which is
self running only in the task I need ( by activating or not the
interrupts). There is no problem here, I'm using flags and semaphores.
This RTC is used to display a decreasing time clock from 9.59
( 9 minutes and 59 seconds ) to 0.00.
The flow of that clock is permanent in the phase I'm talking about even
the output command is not because in the same task I need to command an
output nibble with the algorithm I was talking about.
My ideea is to forget about the minutes and to read the seconds every time
I want an output command.
Then keeping the command ON a number of seconds equal with percentage/10
and OFF the number of seconds equal with ( 100 - percentage )/10 ,
should provide the output I need... But how to deal with a 0 second reading
( for example at 3.00 ) ? I could test the seconds and if are 0 to wait until
are changing...

I think this is the partial answer for my problem... there is an easyest
way ?

Thank you,
Vasile

On Mon, 1 Apr 2002, Olin Lathrop wrote:

{Quote hidden}

--

On Tue, 2 Apr 2002 09:40:04 +0300, Vasile Surducan wrote:

>Thanks all guys ( Bob, Olin and Joe in mail receiving order )
>As usual, language bariers have stopped me to put the right question.
>
>Bob, I need a finest resolution so every time the minimum period will be
>10 seconds and no more, for 10 minutes and 10% I need to do 60 times 1
>second on and 9 secons off.
>

Sorry, my misunderstanding. I didn't pick up on the minimum period
requirement. BTW, after re-reading my earlier post, I wasn't really
trying to be a smart-a\$\$ (even though it may have appeared that way.)

Regards, Bob

--

On Mon, 1 Apr 2002, Bob Barr wrote:

> On Tue, 2 Apr 2002 09:40:04 +0300, Vasile Surducan wrote:
>
> >Thanks all guys ( Bob, Olin and Joe in mail receiving order )
> >As usual, language bariers have stopped me to put the right question.
> >
> >Bob, I need a finest resolution so every time the minimum period will be
> >10 seconds and no more, for 10 minutes and 10% I need to do 60 times 1
> >second on and 9 secons off.
> >
>
> Sorry, my misunderstanding. I didn't pick up on the minimum period
> requirement. BTW, after re-reading my earlier post, I wasn't really
> trying to be a smart-a\$\$ (even though it may have appeared that way.)
>
No, it doesn't for me...

sincerely regards, Vasile

--

Vasile Surducan <PICLISTmitvma.mit.edu> wrote:

> I need a finest resolution so every time the minimum period will be 10
> seconds and no more, for 10 minutes and 10% I need to do 60 times 1
> second on and 9 secons off.

Ah, ok... NOW I understand.  I, too, was puzzled when I saw that
question coming from you.

Something like this should work; it is -- as so many things are --
a
variation on the Bresenham line-drawing algorithm:

; Enter with duty-cycle (0-100) in DUTY.  This routine uses a
; register called SWITCH which must not change between calls
; to the routine.  Note that I'm assuming RADIX=DEC.

TIMER_INTERRUPT:

TSTF    DUTY
BNZ     TESTSW

MOVLW   -1
MOVWF   SWITCH

TESTSW:

BTFSS   SWITCH,7
GOTO    TURNON

BCF     OUTPUT_PIN
GOTO    FINISH

TURNON:

BSF     OUTPUT_PIN

MOVLW   100
SUBWF   SWITCH

FINISH:

MOVF    DUTY,W

This will ALWAYS produce the minimum PWM period necessary for a
particular duty-cycle.  In other words, DUTY=50 will result in

ON-OFF
ON-OFF
etc.

and DUTY=10 will result in

ON-OFF-OFF-OFF-OFF-OFF-OFF-OFF-OFF-OFF
ON-OFF-OFF-OFF-OFF-OFF-OFF-OFF-OFF-OFF
etc.

-Andy

=== Andrew Warren - aiwcypress.com
===
=== Principal Design Engineer
=== Cypress Semiconductor Corporation

--

Thanks Andrew,
I have solved the problem in the same time when I have asked the question

You know what a good teacher said:
"I have explained the problem to my students once, then twice and they
don't understood, third time almost I have understood the problem but they
still don't understood...What should I do with them ?"

I have do it almost in the same fashion like you say here... but I was
using 6 fixed time point comparations with the flowing seconds.
Thanks for the tip.
Vasile

On Tue, 2 Apr 2002, Andrew Warren wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

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