'How to use varible to replace DEFINE?'
I have a question which I believe I should already know, but I am drawing a
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
BTFSS _C ; Skip if W>=PWMphases
ADDLW PWMPHASES ; Adjust back
Thanks in advance
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.
You may do it this way:
;other register definitions
MOVLW -30 ;initialize
MOVWF NPWMPHASES ;
LOOP INCF PHASE
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- New search...