I'm not a PIC programmer but I need to understand the following program.
Actually I want to convert it to an atmel program. Please help.
Moderators note: Please use code tags for pieces of code
Actually I want to convert it to an atmel program. Please help.
Code:
[FONT=Courier New]' Coding for PIC16F72
' Numerical Relay
Include "numrly.inc"
Declare ADIN_RES 8 ' 10-bit result required
Declare ADIN_TAD FRC ' RC OSC chosen
Declare ADIN_STIME 50 ' Allow 50us sample time
Symbol VOLT_IN PORTA.0
Symbol CURRENT_IN PORTA.1
Symbol FREQ_IN PORTC.2
Symbol SYNC_IN PORTC.1
Symbol FIELD_VOLT_IN PORTC.0
Symbol IMP_RELAY PORTB.0
Symbol FREQ_RELAY PORTB.1
Symbol CUR_REV_RELAY PORTB.2
Symbol OVER_VOLT_RELAY PORTB.3
Symbol FIELDFAIL_RELAY PORTB.4
Low PORTA
Low PORTB
Low PORTC
' |76543210|
TRISA = %11111111
TRISB = %00000000
TRISC = %11111111
ADCON1 = %00000000
' Set analogue input on PORTA.0
Dim VOLT As Word
Dim CURRENT As Word
Dim FREQ As Word
Dim RPM As Word
Dim RPMVal As Float
Dim Err As Byte
Dim CntVal As Byte
Low PORTB
DelayMS 3000
Err = 0
Loop:
VOLT = ADIn 0
CURRENT = ADIn 1
RPM = ADIn 2
If CntVal <= 1 Or CntVal = 4 Then
FREQ = Counter FREQ_IN, 1000
End If
VOLT = VOLT * 10
CURRENT = CURRENT * 10 / 5
RPMVal = RPM * 16.123
If (VOLT / CURRENT) < 5 Then
FIELDFAIL_RELAY = 1
IMP_RELAY = 1
Err 0# = 1
Else
IMP_RELAY = 0
Err 0# = 0
End If
If SYNC_IN = 1 And FREQ < 475 Then
FIELDFAIL_RELAY = 1
FREQ_RELAY = 1
Err 0.1 = 1
Else
FREQ_RELAY = 0
Err 0.1 = 0
End If
If VOLT > 1300 Then
FIELDFAIL_RELAY = 1
OVER_VOLT_RELAY = 1
Err 0.2 = 1
Else
OVER_VOLT_RELAY = 0
Err 0.2 = 0
End If
If RPMVal < 2844 Then ' < 1768 Then 'rpmFIELDFAIL_RELAY = 1
CUR_REV_RELAY = 1
Err 0.3 = 1
Else
CUR_REV_RELAY = 0
Err 0.3 = 0
End If
If FIELD_VOLT_IN = 0 Or Err > 0 Then
If CntVal >= 1 Then
FIELDFAIL_RELAY = 1
If CntVal < 4 Then
CntVal = CntVal + 1
End If
Else
CntVal = CntVal + 1
End If
Else
FIELDFAIL_RELAY = 0
CntVal = 0
End If
GoTo LOOP
End[/FONT]
Attachments
-
72.7 KB Views: 25
Last edited by a moderator: