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.

Dual Channel System With PIC16F887

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
hi there friendZzz...!

I am working on multiple channel ADC to RS232 using PIC16F887
Now the problem is that I want to build dual channel EEG systems which transmit data of both channel to the serial Comm (PC) simultaneously...
Something like this ...

For example: when I get output 8 bits for each channel, the Data bytes should take turns, i.e., I have to program the uC internally to send out the data like this. See below:

EEG Channel A ->
|-->uC / PIC--> Data A, Data B, Data A, Data B, -> uC Serial port
EEG Channel B ->

What i have tried so far is the code below...

unsigned short temp_res;
unsigned short temp_res1;
char buf[7];
char buf2[7];
int i;
void main() {
UART1_Init(19200);
ADCON1 = 0x80;
TRISA = 0xFF;
ANSEL = 0xFF; // Configure AN2 pin as analog
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;

TRISA = 0x03; // PORTA is input
TRISD = 0; // PORTC is output
TRISB = 0; // PORTB is output


do {
temp_res = ADC_Read(1)>>2 ;
PORTD = temp_res;
ByteToStr(temp_res,&buf2);
temp_res1 = ADC_Read(0)>>2 ;
PORTB = temp_res1; // Send lower 8 bits to PORTB
ByteToStr(temp_res1,&buf);

for(i = 0; i < 7; i++)
{
UART1_Write(buf2);
Delay_ms(10);
UART1_Write(buf);

}
} while (1);
}

The program above shows output on terminal like this 49341
but it must be like this 94143 (because I applied 2.8V on AN0 and 1.85 on AN1)
Sorry,, If I have done something really stupid in the code :-D because I am very beginner for PIC programming so I really need help...
If u ppl can guide me for my purpose in some more better way then I will be really thankful to all of u ...
Thank u .. :)
 

Are you trying to accquire the ADC simultaneously, if so, you cannot do it with PIC, as it only allows one channel at a time. You need some ADC chip to do it :)
 

I guess buf and buf2 holds the two digital values as string...
Then why you are sending one character from buf and the next character from buf2?
I think you need to send buf full and there after buf2 like:
for(i = 0; i < 7; i++)
{
UART1_Write(buf);
Delay_ms(10);
}
for(i = 0; i < 7; i++)
{
UART1_Write(buf2);
Delay_ms(10);
}

Now if the values displayed are reverse then just reverse the for loop (count down from 6 to 0)
 
Why my PIC ADC cant read AC (sine wave) inputs.. it is showing wrong code at the o/p even after using level shifter..
I have made VDR circuit as a clamper cirucit ...
Kindly help....! :(:-|
 

post your complete code.

Also, what is the range of voltage applying at PIC ADC channel ? (min:max)

And how you are measuring the change at digital o/p?

What about the reference voltage? Is it fixed or variable?
 

There is my code uptill now...
And the clamper circuit and anti aliasing filter I am using i also here..
Code:
unsigned int temp_res;
 char buf2[6];
 int i;
void main() {
  UART1_Init(19200);
  ADCON1 = 0x80;
  ADCON0=0xC1;
  TRISA  = 0xFF;
  ANSEL  = 0xFF;              // Configure AN2 pin as analog
  //ANSELH = 0;                 // Configure other AN pins as digital I/O
  C1ON_bit = 0;               // Disable comparators
  C2ON_bit = 0;

  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
  wordToStr(temp_res,buf2);

    for(i = 0; i < 6; i++)
    {
      UART1_Write(buf2[i]);
      Delay_ms(80);
      }} while(1);
      }
When I am changing MCU clock frequency from 8 MHz to 100 Mhz so my signal become much better after ADC sampling (at ADC input) .. But this is too high clock frequency .. ? :shock:
Thank u for the help...
 

Hi ,, I got it .. see my wave form .. What u say i think now it is sampling good.. :-D
But there is problem with my clamper circuit.. Rite because -ve is still nearer to zero.. :roll:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top