I have the below program and want it to generate the following pwm signals.
1) 2khz HPWM this is working fine as shown by scope.
2) 25hz 50% duty SPWM this is working fine as shown by scope.
3) 25hz 7% duty SPWM this is not working correctly and is broken up and irregular.
4) 12hz Manual pause defined PWM, again this is not working correctly and the led I have to check the loop is not working
The loop1 is is not executing for some reason.
Perhaps something in my config/register setup?
It uses Darrells Instant interrupts and SPWM but I can't see anything obviously wrong. Can you?
Code:'------------------------------ General configuration -------------------------- #config __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _FCMEN_OFF __config _CONFIG2, _PLLEN_OFF & _LVP_OFF #ENDCONFIG DEFINE OSC 16 'Set PicBasic Pro processor speed to 16 Mhz (Must match oscillator value) OSCCON = %01111010 'Sets internal osc to 16 Mhz (Default) TRISA = %00000000 'PortA All Outputs ; Initialize your hardware first CLEAR INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "SPWM_INT.bas" ; Software PWM module DEFINE SPWM_FREQ 25 ; SPWM Frequency DEFINE SPWM_RES 100 ; SPWM Resolution DutyVar1 VAR BYTE DutyVar2 VAR BYTE 'Port Aliases MotFsb VAR PORTA.4 'Define Pin A4 as MOTFSB RedLed VAR PORTA.1 'Define Pin A1 as RedLed ASM SPWM_LIST macro ; Define Pin's to use for SPWM SPWM_PIN PORTA, 0, _DutyVar1 ; and the associated DutyCycle variables SPWM_PIN PORTA, 5, _DutyVar2 ; Notice the underscore before variables 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 ;_____________________________________________________________________________ Main: ; Simple Demo HPWM 1, 127, 2000 'Start 2khz 50% Duty HPWM DutyVar1 = 7 'Set MOTSTB to 7% Duty SPWM DutyVar2 = 50 'Set MOTFSA to 50% Duty SPWM Loop1: 'Bit Bang 12hz PWM HIGH MotFsb Pause 37 LOW MotFsb Pause 45 toggle RedLed goto Loop1





Bookmarks