I am trying to use timer0 interupt to create 4 PWM outputs.
I do not seem to be able to get a counter to increment in the ISR.
Code: Select all
program Usart_lib
DIM COUNT as byte
DIM PWMCOUNT as byte
sub Procedure interrupt
COUNT = COUNT +1
if COUNT = 6
THEN PWMCOUNT = PWMCOUNT +1
COUNT= 0
' if PWMCOUNT >= 254
' then PWMCOUNT = 0
' else
' end if
else
end if
TMR0 = 10
INTCON = $20
end sub
Sub Procedure PWM_out(dim byref pwmcount,red,green,blue,white as byte)
if red <= pwmcount
then PortB.4 = 0
else
portB.4 =1
end if
if green <= pwmcount
then PortB.5 = 0
else
portB.5 = 1
end if
if blue >= pwmcount
then Portb.6 = 0
else
portb.6 =1
end if
if white >= pwmcount
then Portb.7 = 0
else
portb.7 =1
end if
end sub
dim i as byte
dim RXCOUNT as word
dim DMXaddress as byte
dim DMXaddress1 as byte
dim DMXaddress2 as byte
dim DMXaddress3 as byte
DIM ChanelR as Byte
DIM ChanelG as Byte
DIM ChanelB as Byte
DIM ChanelW as Byte
'DIM DimrVal as byte[20]
DMXaddress = 5
DMXaddress1 =6
DMXaddress2 =7
DMXaddress3 = 8
trisa=0
trisb=0
trisc=$80
trisd=0
PWMCOUNT = 0
COUNT = 0
OPTION_REG = $87
TMR0 = 10
INTCON = $20
PORTC = 0
main:
Usart_init(250000) ' Initialize USART module (8 bit, 250000 baud rate, no parity bit...
rcsta.7 = 1 ' use 9th data bit
while true
if Usart_Data_Ready = 1 then ' If data is received:
'i= i+1
i = Usart_Read ' Read the received data
IF RCSTA.2=1 then
RXCOUNT = 0
'i=1
ELSE
INC (RXCOUNT)
end if
If RXCOUNT = DMXaddress+1 then
ChanelR = i
else
If RXCOUNT = DMXaddress1+1 then
ChanelG = i
else
end if
if RXCOUNT = DMXaddress2+1 then
ChanelB = i
else
end if
if RXCOUNT = DMXaddress3+1 then
ChanelW = i
else
end if
end if
end if
PWM_out(PWMCOUNT,ChanelR,ChanelG,ChanelB,ChanelW)
PORTA = ChanelB
';PORTB = ChanelR
PORTD = ChanelW
wend
end.
The code riads in data via serial port. This data is in a long string up to 255 bytes I use a counter to pick of the bytes i am intrested in.
This seems to work fine I can display the information I am sending on LEDs.
I cannot seem to get TMR0 to work though. Can anyone see if I am doing anything wrong.
Thanks