Pic clocked at 40mhz
Code: Select all
program Get to work
' Declarations section
dim current_duty, old_duty, current_duty1, old_duty1 as word
pwm_period1, pwm_period2 as word
dim i as word
dim count as word
dim prevcount as word
dim prevcount2 as word
dim L as bit
dim Value as integer
sub procedure Initsubsys()
TRISC.7=0 ' as input for uart1 read
TRISC.6=1 ' as output for uart1 write
TRISB.10=1 ' as output for PWM
TRISB.11=1 ' as output for PWM
Unlock_IOLOCK()
PPS_Mapping(11, _OUTPUT, _OC2) ' Sets RPx pin 10 to be PWM
PPS_Mapping(10, _OUTPUT, _OC1) ' Sets RPx pin 11 to be PWM
PPS_Mapping(22, _OUTPUT, _U1TX) 'mapping RPx pin 22 as uart1 output
PPS_Mapping(23, _INPUT, _U1RX) ' mapping RPx pin 23 as uart1 input
Lock_IOLOCK()
UART1_Init(9600) ' Initialize UART module at 9600 bps
Delay_ms(100) ' Wait for UART module to stabilize
UART1_Write_Text("Starting:")
PWM_Init(5000 , 1, 1, 2)
PWM_Init(10000 , 2, 1, 3)
PWM_Start(1)
PWM_Start(2)
PWM_Set_Duty(0, 1) ' Set current duty for PWM1
PWM_Set_Duty(0, 2) ' Set current duty for PWM2
UART1_Write_Text("Setup Done:")
end sub
sub procedure InitSensors()
PortB.8 = NOT PortB.8
Delay_ms(150)
PortB.8 = NOT PortB.8
Delay_ms(150)
PortB.8 = NOT PortB.8
Delay_ms(150)
PortB.8 = NOT PortB.8
Delay_ms(150)
PortB.8 = NOT PortB.8
Delay_ms(150)
PortB.8 = NOT PortB.8
Delay_ms(150)
PortB.8 = NOT PortB.8
Delay_ms(150)
PortB.8 = NOT PortB.8
end sub
main:
Initsubsys()
TRISB.8 = 0
SetBit(PORTB, 8)
UART1_Write_Text("Menu? ")
'Delay_ms(1000)
if ( UART1_Data_Ready() = 1) then
UART1_Write_Text("1) T/C ")
UART1_Write_Text("2) NOx / OX ")
UART1_Write_Text("3) Current ")
UART1_Write_Text("3) Reset ")
UART1_Write_Text("5) About")
end if
InitSensors()
while (TRUE) ' endless loop
count = count + 1
'UART1_Write(count)
Delay_ms(1)
if (count = prevcount + 250) then
prevcount = count
PortB.8 = NOT PortB.8
end if
if (count = prevcount2 + 50) then
prevcount2 = count
if Value <= 300 then
UART1_Write_Text(" PWM: ")
UART1_Write(Value)
PWM_Set_Duty(Value, 1)
PWM_Set_Duty(Value, 2)
else
Value = 0
end if
end if
wend
end.
1) I had serial working then it just stopped... any ideas?
2) This Pic has 4 PWM's. I had one working(OC1) but when trying to get both working they both stopped functioning... any Ideas?
3) I am working on a "scheduler" for programs on the pic...It is pretty terrible. Any ideas on how to improve?
Thanks for any help!
Rick