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.

PIC16F877A ::: ADC problem At higher frequency

Status
Not open for further replies.

illegal121

Member level 2
Joined
Jun 20, 2011
Messages
49
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Oman
Activity points
1,650
Hello Friends...

here is my code for PIC16F877A using two 10bit ADC ..
Code:
unsigned int temp_res;
unsigned int temp_res1;
 char buf2[6];
 char buf[6];


 int i;
void main() {
 UART1_Init(9600);
 delay_ms(100);
   TRISA  = 0xFF;
  CMCON = 0x07;
  TRISA  = 0xFF;              // PORTA is input
  TRISC  = 0;                 // PORTC is output
  TRISB  = 0;                 // PORTB is output

  do {
    temp_res = ADC_Read(0);   // Get 10-bit results of AD conversion
    PORTB = temp_res;         // Send lower 8 bits to PORTB
    PORTC = temp_res >> 8;    // Send 2 most significant bits to RC1, RC0
    temp_res1=ADC_read(1);
   WordToStr(temp_res,buf2 );
    for(i = 0; i < 6; i++)
   {
      UART1_Write(buf2[i]);          //Write Channel 0
       Delay_us(1);
     }
     UART1_Write(13);                    //
       WordToStr(temp_res1,buf );
      for(i = 0; i < 6; i++)
   {
                                        // Write channel 1
      UART1_Write(buf[i]);
      Delay_us(1);
     }
      }
     while(1);
              }
PIC ADC is giving enough samples of sinewave below 5-7 Hz and that is reconstructing perfectly using this program but as I am changing frequency and moving above 10 Hz there is not enough sample by ADC to reconstruct sinewave as it is...
I know that changing baud rate (increasing) will give more good result but even when I have changed baud rate to 57600 so it reconstruct upto 20 Hz
I have to reconstruct atleast upto 50 Hz..
Hope you people Helps me out....
 

Can you verify exactly how fast you are sampling your input? How do you establish the sample rate? What does the ADC_Read routine do? What does the UARTn_Write routine do? The first thing I would do is check the timing of your loop and see exactly how long it takes to go around it once. My suspicion is that either your UART routine or ADC Read routine is taking a lot longer than you think. You are either not sampling the input fast enough, or you are spending too much time in the UART routine so that you are missing samples. I think the debugger allows you to look a trace with timestamps on the operations.
 

I am using 9600 baud rate and 20Mhz crystal oscillator ..
ADC_Read read ADC outputs and UART1_Write writes the data means transmitting to serial port...
Yup I have changed loop timing in micros so it can loops as fast as possible...
 

I have given delay of 1 us ...
Data is coming too fast on the terminal ...
But there is not enough sample Like this
18
612
69
0
0
555
285
0
0
442
446
0
0
284
556
0
0
93
610
0
0
0
578
228
0
0
484
399
0
0
336
527
0
0
153
599
0
0
0
603
146
0
0
532
329
0
0
405
479
0
0
236
575
0
0
41
610
47
0
0
565
264
0
0
459
427
0
0
304
545
0
0

---------- Post added at 18:47 ---------- Previous post was at 18:46 ----------

these are not constructing my input wave
 

Yes, you have given a 1uS delay, but that is just added to however long it actually takes to go around the loop. We still need to know: how long does it take to process the loop.

When you used a low frequency input, how many samples did you get per cycle? That will tell you approximately what your loop time is.
 

9600/10 bits = 960 bits/sec
there are 4 character data 3 for my two ADC channel (10 bits) and 1 for CLRF
so 960/4=240Values/Sec
if I give 5 hz then 240/5 =48 sample/sec
and if I am giving 50hz then 240/50 =4.8samples/sec
If I am not wrong about above calculation ....?
See the result when 5 hz is applied
584
554
512
462
402
335
261
184
102
18
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
(for time being there is no negative voltages I will clamp the wave later on )
 

Yes, your calculation looks right (but it STILL doesn't tell us what the ACTUAL loop time is.) Your calculation assumes that it takes zero time for your ADC handler.

Regardless, from your data, which doesn't show a complete cycle, let's assume that 584 is your peak value. That would imply that it takes about 11 cycles to go from peak to zero, that's 1/4 cycle, so it sort of agrees with your 48 samples/input cycle (not 48 samples/sec). 240 samples/sec for two channels==> 120 samples/sec/channel==>60Hz maximum input frequency (nyquist)

The fact of the matter is, if you really are sampling at 120 samples/sec, you should be able to see your 10Hz sinewave. I suspect that your 10Hz input is not really 10 Hz.
 

wait something going wrong :???:

When I changed the frequency 75 hz it sampled very well but not sampling well at 30 or 40 or 50 hz ..
this is plot of sampled at 75 HZ:shock:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top