If anyone is interested, here is what I used to run the simulation (my controller has an LCD)
Code:
#CONFIG
__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF
#ENDCONFIG
DEFINE OSC 8 'LETS PBP KNOW THE OSCILLATOR IS RUNNING AT 8MHz
DEFINE NO_CLEARWDT 1 'NO WATCHDOG TIMER - FOR NOW - WILL DO OUR OWN CLRWDT
OSCCON = %01110001 '8 MHz INTERNAL OSCILLATOR, INTERNAL OSCILLATOR IS USED FOR SYSTEM CLOCK
DISABLE 'NO PBP INTERRUPTS NO PBP DEBUG
' Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 4
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 5
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 1500
' Set data delay time in us
DEFINE LCD_DATAUS 44
'// Set up hardware registers, ADC etc here (not shown) //
ADValue VAR WORD '<---This is your variable.
SetPoint VAR WORD '<---This is your variable.
COUNTER VAR BYTE
RUN_IND VAR BYTE
INCLUDE "incPID.pbp" 'Include the PID routine.
'These variables are declared by the incPID routine but
'the user needs to assign values to them.
pid_Kp = $0700 'Set Kp to 7.0 GAIN
pid_Ki = $0080 'Set Ki to 0.5 RESET
pid_Kd = $0001 'Set Kd to 0 (Derivative not necessary)
pid_Ti = 8 'Update I-term every 8th call to PID
pid_I_Clamp = 100 'Clamp I-term to max ±100
pid_Out_Clamp = 255 'Clamp the final output to 0 to 255
Setpoint = 230 '<---Set desired position.
RUN_IND = 1
START:
FOR ADVALUE = 225 TO 235 'TEST A BUNCH OF VALUES
FOR COUNTER = 1 TO 10
pid_Error = Setpoint - ADValue 'Calculate the error
Gosub PID 'Result returned in pid_Drive
if pid_Out.15 then pid_out = 0 'IF NEGATIVE THEN SHUT OFF FAN
pid_Out = ABS pid_Out 'Convert from two's comp. to absolute
' HPWM 1, pid_Out, 10000 'Set PWM output
LCDOUT $FE, 1, "AD=", DEC ADVALUE, " PO=", SDEC PID_OUT
LCDOUT $FE, $C0, "RUN #", DEC COUNTER, " SETP ", DEC SETPOINT
Pause 1000 'Wait....
NEXT COUNTER
NEXT ADVALUE
IF RUN_IND = 1 THEN
RUN_IND = 0
GOTO START 'DO IT AGAIN SO THAT ITS AS IF THE TEMPERATURE DROPPED
ENDIF
LCDOUT $FE, 1, "DONE!"
DO
LOOP 'ENDLESS LOOP
END
Bookmarks