Can someone cast an eye over this code please.
8mhz pic. Trying to generate 200hz HPWM.
Duty seems stuck at about 60% whatever I try even when it's supposed to be off and idling high with
Duty set at 255. Scope shows pwm is working at 200hz but I can't vary the duty.
Does the Duty variable have to be a WORD?
Confused.
Code:
#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 8 'Set PicBasic Pro processor speed to 8 Mhz (Must match oscillator
value)
OSCCON = %01110010 'Set osc 8mhz and stable
TRISA = %00101001 'PortA Output on Pin A1,A2,A4 & Input on A0,A3,A5
ANSELA = %00000000 'All Digital I/O
APFCON = %10000100 'Set Tx/Rx function to RA4 & RA5
ADCON0 = %00000000 'ADC Disabled
OPTION_REG = %01111111 'Global Enable Weak Pull Ups
WPUA = %00011011 'Weak Pull Up enabled on Ports A0 A1 A3 A4
DEFINE HSER_BAUD 10400 'Set Baud rate to 10400bps
DEFINE HSER_BITS 9 'Set to 9 bit mode
DEFINE HSER_EVEN 1 'Set Even Parity
DEFINE HSER_CLROERR 1 'Clear overflow error automatically
DEFINE CCP1_REG PORTA 'HPWM channel 1 pin Port A Fan PWM Driver
DEFINE CCP1_BIT 2 'HPWM channel 1 pin Bit 2
'*******************************************************************************
'Variables Constants and I/O definitions
'------------------------ Variables 16bit --------------------------------------
FanSpeed var byte 'Ipu Fan Speed Pwm Setting
Start:
FanSpeed = 255
HPWM 1, FanSpeed, 200 'Change/Start 200hz HPWM 'Set Duty 0 = Off 255 = FullOn
end
Bookmarks