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 support@ccsinfo.com

Can my program send and receive data through FPGA?

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



Joined: 23 Jun 2013
Posts: 1
Location: singapore

View user's profile Send private message

Can my program send and receive data through FPGA?
PostPosted: Wed Aug 14, 2013 1:48 am     Reply with quote

Code:

#include <mcu codes.h>
#include <usb_cdc.h>

#define input_CLK PIN_B0 
#define pin_1 PIN_B3
#define input_data PIN_B4
#define input_LED PIN_D1

 void main() 
 {     
    usb_cdc_init();
    usb_init();
    usb_wait_for_enumeration();
     
    int1 data[4];
    int i;
    int1 received_data=0;
    int1 data_input=0;
    int1 data_input1=0;
     
    output_high(input_LED); 
     
    while(!usb_cdc_kbhit())
    {
      for(i=0; i<4; i++)
     {
         data[i] = i+1;
     
         switch(data[i])
      {
      case 1: data[0] = 1;
      break;
      case 2: data[1] = 0;
      break;
      case 3: data[2] = 0;
      break;
      case 4: data[3] = 1;
      break;
      }
       
      output_bit(pin_1, data[i]);
       
      delay_ms(100);
      output_high(input_CLK);
      delay_ms(100);
      output_low(input_CLK);
      delay_ms(100);
      }
       
      output_low(input_LED);
      delay_ms(100);
       
    for(i=0; i<8; i++)
    {
      output_high(input_CLK);
      delay_ms(100);
      output_low(input_CLK);
      delay_ms(100);
      received_data = input_State(input_data);


         if(received_data==1)
         {   
           data_input += received_data;
           printf(usb_cdc_putc,"%d", data_input);
         }
         else
         {
            if(received_data==0)
         {
            data_input1 += received_data;
            printf(usb_cdc_putc,"%d", data_input1);
         }
         
    }
 }         
    }
    } 

I am getting the output data of 1010 instead of 1001 by using oscilloscope to test on pin_1.
_________________
nothing to add
Ttelmah



Joined: 11 Mar 2010
Posts: 19470

View user's profile Send private message

PostPosted: Thu Aug 15, 2013 8:23 am     Reply with quote

1) Without telling us what your FPGA is programmed to do, we can't help.
2) Timings seem ludicrous. When I'm clocking things into a shift register on a FPGA, I'm using single cycle delays, if at all. Hundreds of mSec!...
3) There is so much code doing nothing, it is impossible to tell what you intend, or what is going wrong. Seems like the most complex way to load 1,0,0,1 into an array it is possible to write:
Code:

int1 data[4] = {1,0,0,1};

4) Avoid declaring variables mid function. Understand that standard C, _does not allow this_. It is _supposedly_ supported in CCS, but is one of those things that has the 'habit' of causing problems. Stick to the standard C format, with variables always declared at the start of a function, or code block.
5) You are incrementing single bit variables. Does this make much sense?....

Yes, plenty of people clock data into, and out of shift registers built using FPGA's, with a PIC.

As a further comment, realise that generating a clock and data stream for data, is what SPI does. Even for an 'odd' transmission length like 4 bits, the supplied software SPI can do this.

Best Wishes
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