|
|
View previous topic :: View next topic |
Author |
Message |
Bryan
Joined: 23 Apr 2005 Posts: 73
|
Strange signalling problem |
Posted: Fri Oct 13, 2006 8:05 pm |
|
|
The code here should be fairly simple to understand - I am attempting to output a signal with predetermined pulse widths from an array which I define before outputting data. The strange thing is that the results read on an oscilloscope don't match the theoretical expectation from looking at the code at all. Here is the code:
Code: |
#include <18F2580.h>
#fuses NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(A)
#use fast_io(B)
#use standard_io(C)
short test[] = {0,1,1,0,1,1,1,0,0,1,1,0,1,0,1};
void signalOut(short buffer[], int length);
void main()
{
int i=0;
short j=0;
set_tris_a(0b10111001);
set_tris_c(0b10111111);
while(1)
{
/*output_low(PIN_A1);
output_high(PIN_A2);
delay_us(32);
output_low(PIN_A2);
delay_us(16);
for (i = 0; i<14; i++)
{
output_high(PIN_A2);
delay_us(8);
if (test[i])
{
output_low(PIN_A2);
}
else if (!test[i])
{
output_high(PIN_A2);
}
delay_us(8);
output_low(PIN_A2);
delay_us(8);
}*/
signalOut(test,15);
delay_us(50);
}
}
/*---------------------------------------------------------------------------*/
void signalOut(short buffer[], int length)
{
int i;
output_low(PIN_A1);
output_high(PIN_A2);
delay_us(32);
output_low(PIN_A2);
delay_us(16);
for (i = 0; i<length; i++)
{
output_high(PIN_A2);
delay_us(8);
if (buffer[i] == 1)
{
output_low(PIN_A2);
}
else
{
output_high(PIN_A2);
}
delay_us(8);
output_low(PIN_A2);
delay_us(8);
}
}
|
As you can see from the code, the commented out portion of main is the body of the function signalOut() because I wanted to see if it was a function issue. Strangely, this garbled the output even worse - my output on the scope not only didn't match the array, but it also had long pulse widths - up to 100us! This should not have been possible from the code (I commented out the call to signalOut() when I put the code in main so it didn't output twice). Any ideas what the problem could be? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 13, 2006 8:22 pm |
|
|
Quote: |
but it also had long pulse widths - up to 100us
#include <18F2580.h>
#fuses NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
|
1. There's no HS fuse for the oscillator. It should be added to the
#fuses statement.
2. If you have interrupts running, this will inject random delays into
your code. If your code creates pulses, some of the pulses will
randomly be increased in length.
3. If you're using PCH version 4.xxx, it may not work. Download
vs. 3.249 from the CCS compiler updates web page, and re-write
your code so it doesn't use arrays of bits, and see if it now works. |
|
|
|
|
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
|