![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Nick Guest
|
2 lines of code, where did I go wrong? hyperterminal |
Posted: Tue Jul 13, 2004 10:14 pm |
|
|
below is my code. I am trying to a printf out to hyperterminal. My settings are 9600, 8-N-1, no flow control. This is what I'm getting
"‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-
#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'
-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%
'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%"
I have a pic16f876 running a HS 20mhz ceramic resontator. I know this setup works because I have a different bin file created with a different compiler and it works fine. All I did was reprogram the chip with the CCS compiler and code.
code below:
#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main() {
while(1)
{
printf("Sampling:");
}
} |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Jul 13, 2004 11:04 pm |
|
|
I tried it with a 20MHz xtal and it was OK.
Perhaps your resonator is a bit off frequency - the tolerance on them is typically about 0.5% compared to a crystal worst case of about 100ppm or 0.01%. |
|
![](templates/subSilver/images/spacer.gif) |
Nick Guest
|
|
Posted: Tue Jul 13, 2004 11:13 pm |
|
|
thanks for the info, I guess I could try at a lower speed, 2400 didnt work either. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Jul 13, 2004 11:55 pm |
|
|
I have a 20 MHz Ceramic Resonator ECS ZTT. Is it a bad brand?
I use the settings HS, is that correct? |
|
![](templates/subSilver/images/spacer.gif) |
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
|
Posted: Wed Jul 14, 2004 1:38 am |
|
|
Could you try the same code with a Xtal of 4 Mhz ?
I had the same printing with a Xtal of 20 and 16 Mhz.
The fault was the PIC. I had one 16F876-4 and not a 16F876-20.
Regard. |
|
![](templates/subSilver/images/spacer.gif) |
Nick Guest
|
|
Posted: Wed Jul 14, 2004 1:57 am |
|
|
the pic says on the outside
pic16f876-20/sp does that mean its for 20mhz only?
Nick |
|
![](templates/subSilver/images/spacer.gif) |
adimotz Guest
|
|
Posted: Wed Jul 14, 2004 2:11 am |
|
|
Maybe you need to use a MAX232 (which is an inverter) between PIC and PC comm port. |
|
![](templates/subSilver/images/spacer.gif) |
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
|
Posted: Wed Jul 14, 2004 2:23 am |
|
|
pic16f876-20/sp is a version for maximum 20 Mhz Xtl, it's OK.
Try with 4 Mhz Xtl and with a MAX 232. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: 2 lines of code, where did I go wrong? hyperterminal |
Posted: Wed Jul 14, 2004 3:12 am |
|
|
Nick wrote: | below is my code. I am trying to a printf out to hyperterminal. My settings are 9600, 8-N-1, no flow control. This is what I'm getting
"‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-
#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'
-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%
'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%'-#1‹Y=%"
I have a pic16f876 running a HS 20mhz ceramic resontator. I know this setup works because I have a different bin file created with a different compiler and it works fine. All I did was reprogram the chip with the CCS compiler and code.
code below:
#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main() {
while(1)
{
printf("Sampling:");
}
} |
When you say you have tried it with other code, was there anything at all 'different' (for instance a different PC!). I have had a suprising number of problems recently, with PC's, having 'off frequency' com ports...
Now looking a the data 'stream' (the actual bit pattern being received, versus the one that should be sent), gives (for the word 'Sampling:'):
011001010010000110010110110000001110000110110010010110001110110011100110001011100
and for the string "1‹Y=%'-#":
010001100011010001010011010010111100010100100011111000011100100010110100011000100
Now normally in a situation like yours, you can look along these patterns to see if they 'align' anywhere, or have common features. The big things that 'leap' out, are that the top pattern has six consecutive '0' bits about 1/3rd the way along. Even if the clock timings were well off, this pattern should be visible as either 5 or 7 consecutive 0 bits in the resulting string. Yet this appears nowhere...
However there is a sort of 'similarity', in the two sections:
0000001110000
000111110000
(about ten characters latter in the second string), which looks the sort of pattern that is seen, if the timing is off by a significant percentage.
Is it possible that the original code was 'tweaked' to compensate for a timing component that is relatively inaccurate?. If you have a scope, you should be able to see/measure the shortest pulse in the data stream. This would give the 'bit time', and should be 104uSec. If this is not the case, then you have found the problem.
If the timing is 'off frequency', then trying a lower rate, won't help, since the percentage error would remain constant...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Nick Guest
|
|
Posted: Wed Jul 14, 2004 4:05 am |
|
|
Thanks for all the help, I dont have a scope at home, but at school I have access to one. I dont have a the Max232 installed, would that give me all this problem? The previous code I wrote was in CC5X and it was a software rs232 printf function and I didnt need a max232 with it. Could the built-in hardware rs232 implementation need it?
Nick |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Jul 14, 2004 4:14 am |
|
|
You definitely need it. The RS232 spec has -3V to -12V for the 'mark' and +3V to +12V for the 'space'.
Laptops cheat a bit here I think, that's probably why you got away with it before, right? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Jul 14, 2004 7:10 am |
|
|
Nick wrote: | Thanks for all the help, I dont have a scope at home, but at school I have access to one. I dont have a the Max232 installed, would that give me all this problem? The previous code I wrote was in CC5X and it was a software rs232 printf function and I didnt need a max232 with it. Could the built-in hardware rs232 implementation need it?
Nick |
Aargh!.
Yes...
RS232, has a standard, where a '1', is transmitted as a -ve voltage, and a '0', as a positive voltage. Line drivers like the MAX232, invert the signals. So the PIC gives a +ve logic '1', and a 0v logic 0, and the Max232 inverts this to meet the RS232 specs. The hardware UART, _requires_ this inversion.
You can generate 5v logic 'psuedo' RS232 (it doesn't meet the signalling requirements of the standard), using 'software serial', but not with the hardware port.
This would definately cause your problem...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|