-
SPWM and DEBUG
Hi all
Is there some problem in using the SPWM code and "debug" together? I use debug with
a VFD display for trouble shooting but have not been able to get it to work when the SPWM technique is used.
Below is a stripped down version of the demo which runs (osc 20) but does not register on the display.
I can use the same hardware setup (16f628a) with different code (no SPWM) and use the display (osc 20) without a problem.
Thanks in advance
'SPWM code
DEFINE OSC 20
CLEAR
CMCON = 7
Define DEBUG_REG PORTA ' Debug PORT
Define DEBUG_BIT 0 ' *** Debug pin Bit-0 ***
Define DEBUG_BAUD 9600 ' *** Debug Baud Rate ***
Define DEBUG_MODE 0 ' Set Serial Mode to Inverted
Define DEBUG_PACING 200 ' Delay 'in Us' between characters sent
Debug $0E 'Clr
Debug $0D 'CR
pause 1000
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "SPWM_INT.bas" ; Software PWM module
DEFINE SPWM_FREQ 40 ; SPWM Frequency
DEFINE SPWM_RES 256 ; SPWM Resolution
DutyVars VAR BYTE[3] ; DutyCycle Variables
DutyVar1 VAR DutyVars[0] ; group them in an array for easy access
DutyVar2 VAR DutyVars[1] ; with FOR loops etc.
DutyVar3 VAR DutyVars[2]
ASM
SPWM_LIST macro ; Define PIN's to use for SPWM
SPWM_PIN PORTB, 0, _DutyVar1
SPWM_PIN PORTB, 1, _DutyVar2
SPWM_PIN PORTB, 2, _DutyVar3
endm
SPWM_INIT SPWM_LIST ; Initialize the Pins
ENDASM
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, SPWMhandler, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
;_________________________________________________ ____________________________
LoopCount VAR WORD
Main: ; Simple Demo to fade/flash some LED's
loop:
FOR LoopCount = 1 TO 4 ; Reapeat 4 times
FOR DutyVar1 = 5 TO 255 step 1
pause 10
next
Debug $0D 'CR ;display
Debug, dec2 loopcount
FOR DutyVar1 = 255 TO 5 step -1
pause 10
next
next loopcount
GOTO loop
-
Hi,
DEBUG uses software delays to bitbang the serial stream out. When using interrupts they will disturb the timing of the bitbanged serial stream. It's not specific to the SPWM routines you're using. Either use a PIC with an USART and use HSEROUT instead of DEBUG or you need to temporarily disable the interrupts while sending your data with DEBUG.
/Henrik.
-
Hserout
Hello,
I added these lines and the display is alive and well.
Thanks
Define HSER_TXSTA 20h ' OUTPUT B2 PIN 8 16f628a
Define HSER_BAUD 9600
HSEROUT[ $0D ] 'CR
HSEROUT[ dec2 loopcount]