Resource clash PWN and s/w uart on a 328l
Resource clash PWN and s/w uart on a 328l
Now that I have the NPT code working I wanted to retro fit it to a previous clock project whereby i had to manually set the time, which is awkward as the display is just a single swept needle.
the needle is driven by PWM, but when i try and add the NPT routines on a s/w uart the rx of the uart doesn't appear to work, using pins 12 & 13. If i comment out the pwm init it's ok.
Is there a clash and is there a solution. I could close the pwm when i want to use the uart as it will only be used every 24 hours for a few seconds.
the needle is driven by PWM, but when i try and add the NPT routines on a s/w uart the rx of the uart doesn't appear to work, using pins 12 & 13. If i comment out the pwm init it's ok.
Is there a clash and is there a solution. I could close the pwm when i want to use the uart as it will only be used every 24 hours for a few seconds.
I have checked for timer clashes using s/w uart and pwm16 and there doesn't appear to be one.
PWM16 uses timer1 and s/w uart uses timer2.
i'll do more testing, but the behaviour i see is that if i comment out hte openpwm statement the serial IO works, if i leave it in the i fail to receive a response from the wifi module.
PWM16 uses timer1 and s/w uart uses timer2.
i'll do more testing, but the behaviour i see is that if i comment out hte openpwm statement the serial IO works, if i leave it in the i fail to receive a response from the wifi module.
I'd like to try to reproduce this. Could you make a simple test case that has just the PWM and SW UART code in it?FFMan wrote:[T]he behaviour i see is that if i comment out hte openpwm statement the serial IO works, if i leave it in the i fail to receive a response from the wifi module.
- Don Kinzer
Try this - if you comment out the open pwn i get a reply, if its active i dont'
Hopefully not some muppetry on my part !
Hopefully not some muppetry on my part !
Code: Select all
option com1speed 115200
public Const snFast as single=50.0
public Const snSlow as single=10.0
PUBLIC CONST byChan as byte=1
Sub Main()
dim by_CommPort as byte =7
dim GPS_RX as byte = 0
dim GPS_TX as byte = 0
dim by_Mask as byte
dim GPSOComS(1 To 30) As Byte 'GPS comms
dim GPSIComS(1 To 90) As Byte 'GPS comms was 200
dim SDIn as byte
by_Mask=bx00001000 'non inverted, 8 N 1
Call OpenQueue(GPSOComS, SizeOf(GPSOComS))
Call OpenQueue(GPSIComS, SizeOf(GPSIComS))
's/w uart testing
Call definecom(3,12,13,by_mask)
Call Opencom(3,9600,GPSIcoms,GPSOcoms)
'Open the PWM
'Call OpenPWM(byChan, snFast, zxFastPWM)
'Call DefineCom(by_CommPort,GPS_RX,GPS_TX,by_Mask) h/w test
'Call OpenCom(by_CommPort, 115200, GPSIComS, GPSOComS) h/w test
debug.print "Start"
sleep (5.0)
Call PutQueueStr(GPSOComs,"AT" & CHR(13) & CHR(10))
debug.print "Read"
while -1
if getqueuecount(GPSIComs)>0 then
Call GetQueue(GPSIcoms,SDIn,1)
debug.print chr(SDIn);
'call putqueuestr(GPSocoms,"!")
end if
wend
End Sub
I used the program below, modified slightly since I don't have the GPS unit. For this test, I use a terminal program on the PC to send/receive on the SW UART channel. The test program simply sends back whatever it receives and also displays the hex code of the received character.FFMan wrote:Try this - if you comment out the open pwn i get a reply, if its active i dont'
I tried it initially on a ZX-328n and when I observed that it worked I switched to a ZX-328L where it seemed to work as well.
Code: Select all
option com1speed 115200
public Const snFast as single=50.0
public Const snSlow as single=10.0
PUBLIC CONST byChan as byte=1
Sub Main()
dim by_CommPort as byte =7
dim GPS_RX as byte = 0
dim GPS_TX as byte = 0
dim by_Mask as byte
dim GPSOComS(1 To 30) As Byte 'GPS comms
dim GPSIComS(1 To 90) As Byte 'GPS comms was 200
dim SDIn as byte
by_Mask=bx00001000 'non inverted, 8 N 1
Call OpenQueue(GPSOComS, SizeOf(GPSOComS))
Call OpenQueue(GPSIComS, SizeOf(GPSIComS))
's/w uart testing
Call definecom(3,12,13,by_mask)
Call Opencom(3,9600,GPSIcoms,GPSOcoms)
'Open the PWM
Call OpenPWM(byChan, snFast, zxFastPWM)
'Call DefineCom(by_CommPort,GPS_RX,GPS_TX,by_Mask) h/w test
'Call OpenCom(by_CommPort, 115200, GPSIComS, GPSOComS) h/w test
debug.print "Start"
' sleep (5.0)
' Call PutQueueStr(GPSOComs,"AT" & CHR(13) & CHR(10))
debug.print "Read"
Do
if getqueuecount(GPSIComs)>0 then
Call GetQueue(GPSIcoms,SDIn,1)
Call PutQueueByte(GPSOcoms, SDIn)
debug.print "got character 0x"; CStrHex(SDIn)
' call putqueuestr(GPSocoms,"!")
end if
Loop
End Sub
- Don Kinzer
Don,
try as i might i can't make this work and i've spent like 4 hours on it. I stripped the processor board out of the project and went through checking all the connections and try PWN chan 2, com port different pins etc.
The I built a test 328n on the breadboard with just the minimal pins, XTAL & capacitors, VCC, gnd x 2 and the comms to the PC pins 1-3 and gnd.
I looped 12 & 13 together so that when its working i get the echo back.
I've tried this with 2 different 328s and a different psu, but my results are always the same.
If i open the pwm, i don't get the echo, if i comment it out i do.
What else could be going on. I'm using the latest download package.
try as i might i can't make this work and i've spent like 4 hours on it. I stripped the processor board out of the project and went through checking all the connections and try PWN chan 2, com port different pins etc.
The I built a test 328n on the breadboard with just the minimal pins, XTAL & capacitors, VCC, gnd x 2 and the comms to the PC pins 1-3 and gnd.
I looped 12 & 13 together so that when its working i get the echo back.
I've tried this with 2 different 328s and a different psu, but my results are always the same.
If i open the pwm, i don't get the echo, if i comment it out i do.
What else could be going on. I'm using the latest download package.
It's the same test case as before, i just can't make it work on 2 test setups. stripped back to nothing just the pins mentioned. Don't need an external device, just a loop back and i don't get the echo, or the characters never get sent. I guess i could pin point which it is.
I can't understand what it could be, i've tried swapping everything even the psu.
I can't understand what it could be, i've tried swapping everything even the psu.
With the first test case you posted, I get "Start", "Read" and "AT" displaying in the debug window with pins 12 and 13 connected. However, the "AT" doesn't show up for five seconds due to the Sleep() call at line 33. At first, I thought that I was observing a replication of your issue but I eventually saw the "AT" confirming that it is working as expected. If I comment out the Sleep() call, the "AT" appears immediately.FFMan wrote:It's the same test case as before, i just can't make it work on 2 test setups.
- Don Kinzer
Oops. I didn't have the OpenPWM() commented out. I now see the behavior that you reported but I don't know why.dkinzer wrote:If I comment out the Sleep() call, the "AT" appears immediately.
Curiously, if I move the OpenPWM() call to after the PutQueueStr() call it works as expected. Further, with the OpenPWM() call in the original position and the loop modified as shown below it also works.
Code: Select all
While -1
if getqueuecount(GPSIComs)>0 then
Call GetQueue(GPSIcoms,SDIn,1)
debug.print chr(SDIn);
'call putqueuestr(GPSocoms,"!")
else
Call PutQueueStr(GPSOComs,"AT" & CHR(13) & CHR(10))
end if
Wend
- Don Kinzer
Interesting
The sleep (5.0) allows the wifi module to connect to the wifi and acquire an ip address, so in the main project the first retrieved message is a 'GOT IP' message.
In the main project I'd like the PWM to run all the time but the NPT to run only every 24 hours. I'm sure I could think of a work around based on your findings or is it your intention to investigate further ?
thanks
The sleep (5.0) allows the wifi module to connect to the wifi and acquire an ip address, so in the main project the first retrieved message is a 'GOT IP' message.
In the main project I'd like the PWM to run all the time but the NPT to run only every 24 hours. I'm sure I could think of a work around based on your findings or is it your intention to investigate further ?
thanks
The Sleep() call isn't the problem. Rather, it is some interaction between the PWM and the software UART or possibly the queue.FFMan wrote:I'm sure I could think of a work around based on your findings or is it your intention to investigate further ?
I do intend to investigate further with the goal of finding the cause of the problem and, if possible, a solution.
- Don Kinzer