Does the code work, but not as you expect? If code doesn't work try to debug using a terminal program on your PC.
The serial receive routine will hold up all operations until your 12f683 senses the receive line go to a low state. Here is a different serial receive subroutine that returns a byte value (RxByte) that could be used for your pwmout temp. Do you see how you can modify and pull the conditional if statement outside of the subroutine, to get the effect that you want?
Sub RCV_RS232
RxWait:
IF SerRx On Then goto RCV_RS232 ;wait for start bit
wait halfbaud us ;do half bit time delay
If SerRx On Then goto RxWait
RxByte = 0
For RxBit = 1 to 8 ;set up to read 8 bits
wait baud us
Rotate RxByte Right
If SerRx On then Set RxByte.7 1
If SerRx Off Then Set RxByte.7 0
Next
wait baud us
End sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A hardware PWM woud work better using the HPWM command. The software solution has a real chance of missing/skipping some frames of data. Scaling back the serial baud rate to say 2400 would be beneficial in terms of timing. So using the software PWM, it would then look like this:
start:
do
If GPIO.0 Off Then goto RxValue ;ready to receive data if line pulled low
pwmout 1, temp, 1
loop
goto start
sub RxValue
SerReceive 1, temp
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm sending it at 1200baud and saying "000" thru "255" but it flickers and does something different every time I send?
does it need to be binary or something? I m using VB6
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you verified communications via a terminal program? Until that is done, there is no way to tell what is wrong. If you wanted to try a shortcut, you could try the aforementioned RCV_RS232 sub. Just define the baud, and halfbaud constants, also change the wait states to 10's of us. You may try 82, 81 baud values also. So for 1200 buad:
#define baud 83 ;change wait states to 10us
#define halfbuad 41
Sub RCV_RS232
RxWait:
IF SerRx On Then goto RCV_RS232 ;wait for start bit
wait halfbaud 10us ;do half bit time delay
If SerRx On Then goto RxWait
RxByte = 0
For RxBit = 1 to 8 ;set up to read 8 bits
wait baud 10us
Rotate RxByte Right
If SerRx On then Set RxByte.7 1
If SerRx Off Then Set RxByte.7 0
Next
wait baud 10us
End sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
so I put this in place of the rxvalue sub mentioned above? and where is the new value stored for the pwm? I put a return connection on my serial line and verified that it is sending out the right numbers as they are getting echoed back to me, but it kinda seems like the pic might only be getting one digit maybe when I'm sending it a three digit number? and thanks for the help by the way, you seem to be pretty quick on your reponces too.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Most likely you need to decode the input because it is in the ascii format? For that, look to the software usart routines (alternate) in the contributors section. There is a bin2ascii sub that could be modified to a receive routine (subtract 48 instead of add 48). You are right in thinking that only only one character/numeral is sent at a time.
RxByte is the returned value from the aforementioned sub.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here what i got, what do you think?
#chip 12F683, 12 'mhz
#config MCLRE=off, WDT=off
#define pwm_out1 GPIO.2
#define RecAHigh GPIO.0 on
#define RecALow GPIO.0 off
dim newval as byte
dim newval1 as byte
dim temp as byte
dir pwm_out1 out 'light
Dir GPIO.0 in 'serial
newval = 0
count = 0
newval1= 50
InitSer 1, r1200,1, 8, 1, none, invert
start:
do
If GPIO.0 Off Then Val0 'ready to receive data if line pulled low
pwmout 1, newval1, 1
if count = 3 then
newval1 = newval
count = 0
newval = 0
end if
loop
goto start
sub Val0
SerReceive 1, temp
temp = temp - 48
newval = newval + temp
count = count + 1
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here is what i have for testing:
#chip 12F683, 12 'mhz
#config MCLRE=off, WDT=off
#define pwm_out1 GPIO.2
#define RecAHigh GPIO.0 on
#define RecALow GPIO.0 off
dim temp as byte
dir pwm_out1 out 'light
Dir GPIO.0 in 'serial
temp = 100
InitSer 1, r9600,1, 8, 1, none, invert
start:
do
SerReceive 1, temp
pwmout 1, temp, 1
loop
goto start
but, i think there is something wrong with it? i want it to send the pwmout over and over while it is waiting for a new serial command.
Does the code work, but not as you expect? If code doesn't work try to debug using a terminal program on your PC.
The serial receive routine will hold up all operations until your 12f683 senses the receive line go to a low state. Here is a different serial receive subroutine that returns a byte value (RxByte) that could be used for your pwmout temp. Do you see how you can modify and pull the conditional if statement outside of the subroutine, to get the effect that you want?
Sub RCV_RS232
RxWait:
IF SerRx On Then goto RCV_RS232 ;wait for start bit
wait halfbaud us ;do half bit time delay
If SerRx On Then goto RxWait
RxByte = 0
For RxBit = 1 to 8 ;set up to read 8 bits
wait baud us
Rotate RxByte Right
If SerRx On then Set RxByte.7 1
If SerRx Off Then Set RxByte.7 0
Next
wait baud us
End sub
guess I dont quite see it?
A hardware PWM woud work better using the HPWM command. The software solution has a real chance of missing/skipping some frames of data. Scaling back the serial baud rate to say 2400 would be beneficial in terms of timing. So using the software PWM, it would then look like this:
start:
do
If GPIO.0 Off Then goto RxValue ;ready to receive data if line pulled low
pwmout 1, temp, 1
loop
goto start
sub RxValue
SerReceive 1, temp
end sub
I'm sending it at 1200baud and saying "000" thru "255" but it flickers and does something different every time I send?
does it need to be binary or something? I m using VB6
No help on the VB6 side of things.
Have you verified communications via a terminal program? Until that is done, there is no way to tell what is wrong. If you wanted to try a shortcut, you could try the aforementioned RCV_RS232 sub. Just define the baud, and halfbaud constants, also change the wait states to 10's of us. You may try 82, 81 baud values also. So for 1200 buad:
#define baud 83 ;change wait states to 10us
#define halfbuad 41
Sub RCV_RS232
RxWait:
IF SerRx On Then goto RCV_RS232 ;wait for start bit
wait halfbaud 10us ;do half bit time delay
If SerRx On Then goto RxWait
RxByte = 0
For RxBit = 1 to 8 ;set up to read 8 bits
wait baud 10us
Rotate RxByte Right
If SerRx On then Set RxByte.7 1
If SerRx Off Then Set RxByte.7 0
Next
wait baud 10us
End sub
so I put this in place of the rxvalue sub mentioned above? and where is the new value stored for the pwm? I put a return connection on my serial line and verified that it is sending out the right numbers as they are getting echoed back to me, but it kinda seems like the pic might only be getting one digit maybe when I'm sending it a three digit number? and thanks for the help by the way, you seem to be pretty quick on your reponces too.
Most likely you need to decode the input because it is in the ascii format? For that, look to the software usart routines (alternate) in the contributors section. There is a bin2ascii sub that could be modified to a receive routine (subtract 48 instead of add 48). You are right in thinking that only only one character/numeral is sent at a time.
RxByte is the returned value from the aforementioned sub.
here what i got, what do you think?
#chip 12F683, 12 'mhz
#config MCLRE=off, WDT=off
#define pwm_out1 GPIO.2
#define RecAHigh GPIO.0 on
#define RecALow GPIO.0 off
dim newval as byte
dim newval1 as byte
dim temp as byte
dir pwm_out1 out 'light
Dir GPIO.0 in 'serial
newval = 0
count = 0
newval1= 50
InitSer 1, r1200,1, 8, 1, none, invert
start:
do
If GPIO.0 Off Then Val0 'ready to receive data if line pulled low
pwmout 1, newval1, 1
if count = 3 then
newval1 = newval
count = 0
newval = 0
end if
loop
goto start
sub Val0
SerReceive 1, temp
temp = temp - 48
newval = newval + temp
count = count + 1
end sub
will this work with incomig ascii?
will this work with incomig ascii?