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

Exact match. Not showing close matches.
PICList Thread
'[PIC]:PWM'
2001\11\30@055757 by Attila Lorincz

flavicon
face
Hello

I use PIC16f628, how can I set the PWM mode for 38 kHz?
The PWM mode work in SLEEP mode?
How I can simulate the PWM mode in MPLAB?
If you have an example with PWM settings please send me.

Thank You



______________________________________________________________________
Do you want a free e-mail for life ? Get it at http://www.personal.ro/

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.



'[PIC]:PWM'
2001\12\03@033432 by Vasile Surducan
flavicon
face
On Fri, 30 Nov 2001, Attila Lorincz wrote:

> Hello
>
> I use PIC16f628, how can I set the PWM mode for 38 kHz?
> The PWM mode work in SLEEP mode?

 I don't know, never tried.

> How I can simulate the PWM mode in MPLAB?

 difficult, you can't simulate in real time, just to see the output pin
is changing value

> If you have an example with PWM settings please send me.

 PWM module is the same like 877 has ( only just one module )

 www.geocities.com/vsurducan/PIC/lib.html
 hardpwm.jal or music.jal, the assemblerm algorithm is the same


 regards, Vasile

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\12\03@082843 by kben

picon face
Hi,
Try these links
www.rentron.com/Infrared_Communication.htm
The above sets up PWM 38khz for a f877, but I had no trouble converting it
for a f628 in CCS C, just get the data sheet from http://www.microchip.com.
http://www.rentron.com/remote.htm
The above is good stuff on ir.

Good Luck,
        Kevin
>On Fri, 30 Nov 2001, Attila Lorincz wrote:
>
>> Hello
>>
>> I use PIC16f628, how can I set the PWM mode for 38 kHz?
>> The PWM mode work in SLEEP mode?
>

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\12\03@090120 by SkinTech

flavicon
face
----- Original Message -----
From: "Vasile Surducan" <spam_OUTvasileTakeThisOuTspamL30.ITIM-CJ.RO>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Monday, December 03, 2001 9:27 AM
Subject: Re: [PIC]:PWM


{Quote hidden}

You can simulate PWM in (almost) real time on the Proteus VSM (lite)
simulator, check out http://www.labcenter.co.uk.

Cheers, Jan Didden

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



'[PIC]:PWM'
2002\04\09@021129 by Simon-Thijs=20de=20Feber?=
flavicon
face
Hello All,

Yesterday evening i have been struggling with a PWM
function.

A char should be loaded with e.g. 0xF0, afterwards
rotated right, and every passing LSB should be put on
a output pin.

So i did this in CC5x

led1 = pwm.0;
pwm = pwm >> 1;

this generates something like

BTFSS pwm,0
BCF   led1
BTFSC pwm,0
BSF   led1
CLR   0x05, C  //clear carry
RRF   pwm,1

The clear carry is not required cause i want a
continues rolling function.

So i removed the "clear carry" in an inline assembly
block and included that in my code, but that has not
solved the problem.

any one an idea ?


grtz

Simon








__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\04\09@033144 by John Dammeyer

flavicon
face
Hi,

You are forgetting that after the rotate the lsb is left in the carry
and what was in the carry is now in the msb.  You can get fancy and
first set the carry to the value of pwm.0 or try the following for fun.

       char LpDec @ pDecArg;
       char HpDec @ pDecArg+1;

       bHB_LED = pDecArg & 1;
       HpDec = LpDec;
       pDecArg >>= 1;

Now although this C code looks overly complex,  look at the code it
makes.  Ignore for the moment that Bytecraft C 1.4 sets the RPx bits for
any jump destination.  The first statement is the same as the bit
operations as if it were a ch.0 test.

One difference with this code is that the value is only tested once.  If
the location were a port pin that was changing from an outside source
the CC5x compiler generates code that might never light the LED since
the first test fails and then the second test fails because the input
value changed.  Very dangerous in real time systems.

Once the LED value is set the shift is kind of neat.  Copy the Least Sig
byte of the word into the upper byte.  Then shift it right one bit.  The
RRF 3F moves the lsb of the 8 bit variable into the carry.  The RRF 3E
then moves that bit into bit 7 and loses the lsb into the carry.

It may look like a waste of memory to use two bytes but you can see the
compiler here just stuffs the character we want to rotate into a
variable used for all sorts of I/O.


08C5 1283    BCF    STATUS,RP0        bHB_LED = pDecArg & 1;
08C6 1303    BCF    STATUS,RP1
08C7 183E    BTFSC  3E,0
08C8 28CB    GOTO   08CBh
08C9 1205    BCF    PORTA,4
08CA 28CE    GOTO   08CEh
08CB 1283    BCF    STATUS,RP0
08CC 1303    BCF    STATUS,RP1
08CD 1605    BSF    PORTA,4
08CE 1283    BCF    STATUS,RP0        HpDec = LpDec;
08CF 1303    BCF    STATUS,RP1
08D0 083E    MOVF   3E,W
08D1 00BF    MOVWF  3F
08D2 1003    BCF    STATUS,C          pDecArg >>= 1;
08D3 0CBF    RRF    3F
08D4 0CBE    RRF    3E


You might want to enter and leave this function with a
       LpDec = pwm;
       ...
       pwm = LpDec;

Or be real sneaky and position your variables so a temporary one is
declared just after pwm.

Example:

unsigned char pwm;
unsigned char i;

unsigned int var16 @ pwm;

Regards,

John Dammeyer



> {Original Message removed}

2002\04\09@033815 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

Yes, you cannot expect the carry bit to contain the previous LSbit of the
pwm variable if you are performing any other operations that set/clear the
carry flag.

What you have to do is preload the carry bit with the LSbit like thisL

       rrf     pwm,w   ; move LSbit into carry, pwm unaffected
       rrf     pwm,f   ; rotate pwm, carry bit now moved to MSbit

Regards

Mike

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\04\09@041430 by John Dammeyer

flavicon
face
Clever!!!

John Dammeyer

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\04\09@044916 by Dag Bakken

flavicon
face
Since you use the operator ">>", you will always have the clear carry
since this operator is supposed to fill in blanks.  What you can do is
this:
    led1 = pwm.0;
    pwm = rr(pwm);

This should do exactly what you are asking.

Dag S


STdF> Hello All,

STdF> Yesterday evening i have been struggling with a PWM
STdF> function.

STdF> A char should be loaded with e.g. 0xF0, afterwards
STdF> rotated right, and every passing LSB should be put on
STdF> a output pin.

STdF> So i did this in CC5x

STdF> led1 = pwm.0;
STdF> pwm = pwm >> 1;

STdF> this generates something like

STdF> BTFSS pwm,0
STdF> BCF   led1
STdF> BTFSC pwm,0
STdF> BSF   led1
STdF> CLR   0x05, C  //clear carry
STdF> RRF   pwm,1

STdF> The clear carry is not required cause i want a
STdF> continues rolling function.

STdF> So i removed the "clear carry" in an inline assembly
STdF> block and included that in my code, but that has not
STdF> solved the problem.

STdF> any one an idea ?


STdF> grtz

STdF> Simon








STdF> __________________________________________________
STdF> Do You Yahoo!?
STdF> Everything you'll ever need on one web page
STdF> from News and Sport to Email and Music Charts
STdF> http://uk.my.yahoo.com

STdF> --
STdF> http://www.piclist.com hint: The PICList is archived three different
STdF> ways.  See http://www.piclist.com/#archives for details.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\04\09@134718 by Dag Bakken

flavicon
face
Sorry about that...  I actually managed to misunderstand.  This is a
correction.  A circular buffer would be something like this, and very
much like another reply you got in asm.

W=rr(pwm);
led1=Carry;
pwm=rr(pwm);

This should generate something like:

   RRF   pwm,W      ; Get bit
   BTFSS Carry      ; Output it
   BCF   led1
   BTFSC Carry
   BSF   led1
   RRF   pwm,F      ; Re-insert

It doesn't really matter.  You can just as well do something like
this:

W=rr(pwm);
pwm=rr(pwm);
led1=pwm.3;


Dag S


STdF> Hello,

STdF> Thanks for the replies.
STdF> Following Dag's hint, since i use CC5x, i found out it
STdF> did not work.
STdF> In MPASM i tried the piece of code which is shown
STdF> below.

STdF> start   clrw
STdF>         CLRF    PORTA
STdF>         BSF     STATUS, RP0
STdF>         MOVLW   0x00
STdF>         MOVWF   TRISA
STdF>         BSF     STATUS, C
STdF>         BCF     STATUS, RP0
STdF>         MOVLW   0x55
STdF>         MOVWF   pwm


STdF> main    BTFSS   pwm,0
STdF>         BCF     PORTA,0
STdF>         BTFSC   pwm,0
STdF>         BSF     PORTA,0

STdF>         rrf     pwm,1
STdF>         goto    main
STdF> ;
STdF> END

STdF> So i filled pwm with 0xAA.
STdF> I'd expected a bit pattern on the output which should
STdF> look like 01010101.
STdF> What i see happening in MPASM, when i trace pwm, is
STdF> 0xAA, 0x55, 0x2A, 0x95, 0x4A, 0xA5, 0x52, 0xA9, 0x54,
STdF> 0xAA. And this continues since pwm is not affected.
STdF> So that is OK.

STdF> However when i try it on my 16F84. I see the 01010101
STdF> pattern and then it stops, and the led i connected at
STdF> that pin stays low.

STdF> What CC5x does with

STdF> led1 = pwm.0;
STdF> pwm = rr(pwm);

STdF> is exactly what is in the main loop.

STdF> As i said, when implemented on my PIC it does not
STdF> work.

STdF> grtz

STdF> Simon


STdF> __________________________________________________
STdF> Do You Yahoo!?
STdF> Everything you'll ever need on one web page
STdF> from News and Sport to Email and Music Charts
STdF> http://uk.my.yahoo.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\04\09@140913 by John Dammeyer

flavicon
face
Hi Dag,

Even more clever.  Learn something new every day.  Here's the Bytecraft
version:

08C5 1283    BCF    STATUS,RP0        WREG = RRF(ch);
08C6 1303    BCF    STATUS,RP1
08C7 0C4A    RRF    4A,W
08C8 1803    BTFSC  STATUS,C          bHB_LED = STATUS.C;
08C9 28CC    GOTO   08CCh
08CA 1205    BCF    PORTA,4
08CB 28CD    GOTO   08CDh
08CC 1605    BSF    PORTA,4
08CD 0CCA    RRF    4A                ch = RRF(ch);

What I especially like about this is that it could be used in a loop to
continually output an 8 bit value to the LED to be captured on the scope
and show what the program is doing in real time.  i.e. Off for 1/2
second,  the pattern on the next half second.  The LED could still blink
or appear to be a heartbeat LED yet with the scope show a nice
diagnostic.

John Dammeyer

> {Original Message removed}

2002\04\09@152721 by Scott Dattalo

face
flavicon
face
On Tue, 9 Apr 2002, John Dammeyer wrote:

> Hi Dag,
>
> Even more clever.  Learn something new every day.  Here's the Bytecraft
> version:
>
> 08C5 1283    BCF    STATUS,RP0        WREG = RRF(ch);
> 08C6 1303    BCF    STATUS,RP1
> 08C7 0C4A    RRF    4A,W
> 08C8 1803    BTFSC  STATUS,C          bHB_LED = STATUS.C;
> 08C9 28CC    GOTO   08CCh
> 08CA 1205    BCF    PORTA,4
> 08CB 28CD    GOTO   08CDh
> 08CC 1605    BSF    PORTA,4
> 08CD 0CCA    RRF    4A                ch = RRF(ch);
>

It is clever, but like the routines posted before it, it has jitter and
it's not isochronous. If you're just dimming an LED, then I suppose it
really doesn't matter.

But if you do care then consider:

  rrf    ch,w
loop
  rrf    ch,f
  skpc
   goto  lo

hi:
  nop
  bsf    IOPORT,IOBIT

  goto   loop

lo:
  bcf    IOPORT,IOBIT

  goto   loop


Or for more more speed, you could unroll the loop:

  btfss   ch,0
   goto   lo_0

  nop

  bsf    IOPORT,IOBIT
  goto   next_bit

lo_0

  bcf    IOPORT,IOBIT
  goto   next_bit

next_bit

...

Of course, a better solution is to forget the bcf/bsf's and do this:


  movlw   (1<<IOBIT)
  btfsc   ch,0
   clrw
  xorwf   IOPORT,F

Or if you're worried about rmw problems:

  movf   IOPORT,w

  andlw  ~(1<<IOBIT)
  btfsc  ch,0
   iorlw (1<<IOBIT)
  movwf  IOPORT

  andlw  ~(1<<IOBIT)
  btfsc  ch,1
   iorlw (1<<IOBIT)
  movwf  IOPORT

... and so on for the next 6 bits

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\04\09@154253 by John Dammeyer

flavicon
face
This is fun isn't it?  8-)

John


{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\04\10@140055 by Simon-Thijs=20de=20Feber?=

flavicon
face
Hello,

I  tried your code Dag.
But since i have some other routines running i see
unwanted behaviour. So i try to switch that off first.

The bit pattern coming out now looks like
00110011001101010100110011001100
and repeats over and over again.

grtz

Simon



--- Dag Bakken <@spam@dagKILLspamspamC74.NO> wrote: > Sorry about
that...  I actually managed to
{Quote hidden}

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2002\04\11@132759 by Simon-Thijs=20de=20Feber?=

flavicon
face
Hello,

W=rr(pwm);
led1=Carry;
pwm=rr(pwm);

The asm of this is not the same as

    RRF   pwm,W      ; Get bit
    BTFSS Carry      ; Output it
    BCF   led1
    BTFSC Carry
    BSF   led1
    RRF   pwm,F      ; Re-insert

The difference is in the last line of asm.
CC5x generates :
RRF pwm,1

instead of

RRF pwm,F

grzt

Simon


--- Dag Bakken <RemoveMEdagTakeThisOuTspamC74.NO> wrote: > Sorry about
that...  I actually managed to
{Quote hidden}

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

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


2002\04\11@135511 by Barry Gershenfeld

picon face
>The difference is in the last line of asm.
>CC5x generates :
>RRF pwm,1
>
>instead of
>
>RRF pwm,F

After they are assembled they will be the same.  "F" is a symbolic
reference to "file register" but the assembler translates it to
a 1, which is what actually goes into the machine instruction.

Barry

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


2002\04\11@151425 by Simon-Thijs=20de=20Feber?=

flavicon
face
Then how come that the functionality differs ?!

grtz

Simon


--- Barry Gershenfeld <RemoveMEbarryspamTakeThisOuTZMICRO.COM> wrote: >
{Quote hidden}

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

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


2002\04\11@191125 by Barry Gershenfeld

picon face
At 08:12 PM 4/11/02 +0100, Simon-Thijs de Feber wrote:
>Then how come that the functionality differs ?!

It would have to be something else.  Maybe all the symbols
should be checked; pvm, Carry, led1, and so on.  Actually,
W and F can be suspect, since "nothing should be different",
yet something is.  If you can get to the output (hex codes
or assembler listing) you can see if anything's different.

I haven't followed this thread so I don't know the details
of your program.

Barry


{Quote hidden}

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


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