Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

12 bit ADC over USB at 10 kHz

Status
Not open for further replies.

itisme

Newbie level 4
Joined
Mar 20, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,330
Hello,

I'm trying sample one channel ADC at 10kHz and transmit the data over USB serial. The code (CCS C) is below.

Unfortunately USB halt after transmitting several tens of samples. I think the problem with the speed of "printf(usb_cdc_putc,...)", but have no idea how to solve it.

I'll appreciate for help.

Code:
#include <18F2553.h> 
#device ADC = 12 
//configure a 20MHz crystal to operate at 48MHz 
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN 
#use delay(clock=48000000) 
//#use rs232(baud = 115200, xmit = PIN_C6, rcv = PIN_C7) 

#include <usb_cdc.h> 
//#include <input.c> 
//#include <stdlib.h> 

unsigned int16 adc_data; 
int32 i=0; 
int8 s2r=1; //s2r - Seconds to record 
int32 c2t; //c2r - Cycles to transmit 

//Initializing the RTOS Program 

#use rtos(timer = 0, minor_cycle = 10us) 

#task(rate = 100us, max = 10us) // 100uS -> 10kHz 
void transmit_over_usb() 
{ 
        //adc_data = read_adc(); 
        printf(usb_cdc_putc, "%Lu\n\r", read_adc()); 
        if(++i==10000)//(i == c2t) 
            rtos_terminate( ); 
} 

void main() 
{ 
   #use standard_io(A) 
    
   setup_adc_ports(ALL_ANALOG); 
   setup_adc(ADC_CLOCK_DIV_64); // for 48MHz OSC 
   //setup_adc(ADC_CLOCK_DIV_16); // For 20 MHz OSC 
   set_adc_channel(0); 
   delay_us(10); 
    
   usb_cdc_init(); 
   usb_init(); 

   while(!usb_cdc_connected()) {} 

   do 
   { 
      usb_task(); 
      if (usb_enumerated()) 
      { 
         wait_usb: // Label 
         while (usb_cdc_getc() != 'r') ; 
         i=0; 
         s2r=1; 
          
         c2t = (s2r*1e6)/250; // How many cycles to transmit the data. NOTE: Denumerator should be equal to "rate" in main RTOS task 
         output_high(PIN_B0); 
          
         rtos_run(); 

         output_low(PIN_B0); 
         // printf("Done!\n\r"); 
         printf(usb_cdc_putc,"5002\n\r"); 
         goto wait_usb; 
      } 
   } while (TRUE); 
}
 

hi itisme.....
I dont know to write a smplie line of code

can you help me to write a programme?
Please check my new thread...........please
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top