Here is the interrupt handler:
Code:'------------------------------------------------------------------------------- ' Interrupt Handler '------------------------------------------------------------------------------- DISABLE INTERRUPT ' No interrupts past this point Main_Interrupt_Handler: '--------------------------------------------------------------------------- ' PortB.0 Interrupt, Motor RPM Counter '--------------------------------------------------------------------------- IF INTCON.1 = 1 THEN IF Calibrating = 1 THEN Total_Pulses = Total_Pulses + 1 ELSE IF System_Calibrated = 1 THEN New_Position_Counter = New_Position_Counter + 1 IF New_Position_Counter >= (Pulses_Per_Position + Temp_Pulses) THEN SELECT CASE Current_Direction CASE Forward_Dir Current_Position = Current_Position + 1 IF Current_Position > Total_Positions THEN Current_Position = 1 ENDIF CASE Reverse_Dir Current_Position = Current_Position - 1 IF Current_Position = 0 THEN Current_Position = Total_Positions ENDIF END SELECT DEBUG 13, 10, "[ Position Change ] Current Position: ", DEC Current_Position, 13, 10 New_Position_Counter = 0 Temp_Pulses = 0 ENDIF ENDIF ENDIF INTCON.1 = 0 ENDIF '--------------------------------------------------------------------------- '--------------------------------------------------------------------------- ' PortB.1 Interrupt, Position 1 Sensor '--------------------------------------------------------------------------- IF INTCON3.0 = 1 THEN DEBUG 13, 10, "[ INTERRUPT ] Home Position Detected", 13, 10 Pos1Found = 1 New_Position_Counter = 0 Temp_Pulses = 0 Current_Position = 1 INTCON3.0 = 0 ENDIF '--------------------------------------------------------------------------- '--------------------------------------------------------------------------- ' PortB.2 Interrupt, Fault Relay Input '--------------------------------------------------------------------------- IF INTCON3.1 = 1 THEN DEBUG 13, 10, "[ INTERRUPT ] AC Invertor Fault Detected", 13, 10 AC_Fault_Detected = 1 INTCON3.1 = 0 ENDIF '--------------------------------------------------------------------------- '--------------------------------------------------------------------------- ' USART Receive Interrupt '--------------------------------------------------------------------------- IF PIR1.5 = 1 THEN 'DEBUG 13, 10, "[ INTERRUPT ] USART Receive", 13, 10 HSERIN [RS485_B0] SELECT CASE RS485_B0 CASE RS485_STX RS485_Receiving_Data = 1 RS485_Bytes_Received = 0 FOR i = 1 TO RS485_Buffer_Size RS485_Data_Buffer[i] = 0 NEXT CASE RS485_ETX RS485_Receiving_Data = 0 RS485_To_Address = RS485_Data_Buffer(0) RS485_Command = RS485_Data_Buffer(1) RS485_Parameter.HighByte = RS485_Data_Buffer(2) RS485_Parameter.LowByte = RS485_Data_Buffer(3) RS485_From_Address = RS485_Data_Buffer(4) RS485_Parameter = RS485_Parameter - 10 CASE ELSE IF RS485_Receiving_Data = 1 THEN RS485_Data_Buffer(RS485_Bytes_Received) = RS485_B0 RS485_Bytes_Received = RS485_Bytes_Received + 1 ENDIF END SELECT PIR1.5 = 0 ENDIF '--------------------------------------------------------------------------- IntDone: RESUME ' Return to main program ENABLE INTERRUPT '-------------------------------------------------------------------------------




Bookmarks