PDA

View Full Version : Using Variables with PAUSE/PWM Commands



RossWaddell
- 10th April 2012, 02:38
I want to be able to set a PAUSE value using a variable at the top of my code so that the same value can be referenced in many places and I only have to change it in one place while experimenting.

FLASH_ON VAR BYTE
FLASH_OFF VAR BYTE


FLASH_ON = 1500
FLASH_OFF = 500

lblLoop:
High LED_0
Pause 1500
Low LED_0
Pause 500

GoTo lblLoop

But this doesn't work, or at least the PAUSE doesn't last as long as I think it should (1.5 seconds the first instance, 0.5 the second).

Can you use variables with PAUSE? If so, are they defined as different types?

What about PWM? I'd like to do the same thing for the Duty & Cycle values.

RossWaddell
- 10th April 2012, 03:42
Should I be using instead:

Symbol FLASH_ON = 1500
Symbol FLASH_OFF = 500

mackrackit
- 10th April 2012, 03:54
FLASH_ON VAR BYTE
FLASH_OFF VAR BYTE
Your values are larger than a BYTE.

HenrikOlsson
- 10th April 2012, 06:10
Yeah, they need to be WORD-size variables to fit values larger than 255....
But if you're not going to change the value at runtime there's no real need to have them as variables, you might as well make them constants:

FLASH_ON CON 1500
FLASH_OFF CON 500

Saves on both RAM and flash memory.

RossWaddell
- 10th April 2012, 12:45
Thanks all! I'll use constants for now but eventually it will read from a pot input.