Searching \ for 'How to use varible to replace DEFINE?' 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/index.htm?key=how+use+varible
Search entire site for: 'How to use varible to replace DEFINE?'.

Truncated match.
PICList Thread
'How to use varible to replace DEFINE?'
1998\10\29@201327 by Jon Petty

picon face
Hello everyone

I have a question which I believe I should already know, but I am drawing a
blank.

In my code I am currently using a #DEFINE PWM_PHASES = 30 statement to set the
frequency rate of PWM. I want to use a variable instead of a define statement
so that I can use a serial transfer to change the frequency on the fly. The
code manipulates PWM_PHASES as a literal.

Can I simply replace the #define with a variable and use literal manipulation
on a variable that is loaded with a literal value like 30?

I think I am missing something---How can I accomplish this? Do I have to
change  ADDLW to a ADDWF to manipulate the variable. The serial transfer will
write a 0-100 value in a variable called B_CHANNEL. I then want to use the
B_CHANNEL value to set PWM_PHASES.

Please see the code snippet

LOOP    INCF    PHASE,W         ; Next pwm phase
       ADDLW   -PWMPHASES
       BTFSS   _C              ; Skip if W>=PWMphases
       ADDLW   PWMPHASES       ; Adjust back
       MOVWF   PHASE

       CALL    SERIAL

Thanks in advance


Jon

1998\10\29@213541 by Regulus Berdin

flavicon
face
Jon Petty wrote:
> Can I simply replace the #define with a variable and use literal manipulation
> on a variable that is loaded with a literal value like 30?
>
> I think I am missing something---How can I accomplish this? Do I have to
> change  ADDLW to a ADDWF to manipulate the variable. The serial transfer will
> write a 0-100 value in a variable called B_CHANNEL. I then want to use the
> B_CHANNEL value to set PWM_PHASES.
As what I understand, you want to make the PWM_PHASES change during
runtime from a value taken for SERIAL routine.

To do this, you must make PWMPHASES a register, not a constant.

{Quote hidden}

You may do it this way:

       CBLOCK  ...
               PWMPHASES
               ...
               ;other register definitions
       ENDC

       MOVLW   -30             ;initialize
       MOVWF   NPWMPHASES      ;
       ...

LOOP    INCF    PHASE
       MOVF    PWMPHASES,W
       SUBWF   PHASE
       SKPC
        ADDWF  PHASE

       CALL    SERIAL


Reggie

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