CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Strange signalling problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Bryan



Joined: 23 Apr 2005
Posts: 73

View user's profile Send private message Send e-mail AIM Address

Strange signalling problem
PostPosted: Fri Oct 13, 2006 8:05 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 13, 2006 8:22 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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