Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Adc Pic16f877a

Status
Not open for further replies.
Presumably you're still talking about a low spec scope connected via serial?, you really need to use the hardware USART - doing it in software is just further crippling your sample rate.
 
hi,
As we keep pointing out, if this is a 'real' application other than a learning exercise,
you are not going to get the results you expect from the project.

If it is a learning exercise, thats fine by me.

If I was trying to write a 'software uart' routine for the 16F877 I would use the internal 'hardware uart' iof the 16F877.
Use a proven RS232 routine and get the 16F877 transmitting/receiving from a PC.

Then, write the software 'receive' routine, [the one you are working on], send characters from the PC to the S/W uart pin
of the 16F877and get your 16F877 H/W routine to send it back to the PC,,, so that you check and verify the S/W routine.

Is that clear?

Although I havn't had a reason to use a PIC S/W uart, I would feel as you are talking 20MHz xtal and a baud rate 115,000,
that the pulse timing is going to be 'tight' and critical.

I am sure other members who have gone this route will be able to give a more meaningful response.
 
ok eric, i'll try it first .. i just want to learn how to have an additional RX pin besides using the original RX build in pin in the PIC so that i can have more than one RX pin that might be useful and act as a RX multiplexer and TX one pin to the UART .
 
Hi Everyone,
I'm new to PIC. I'm trying to do the ADC using PIC16F877A. For example if input ADC RA0 more than 2.5 V then the LED at RD0 is ON and if input ADC RA0 less than 2.5 then LED at RD1 is ON. I need a help. Can i get the assembly code. I'm confused what are the register i have to enable. Please help me. if everyone who know the code in assembly please give know or e-mail me at edy_tse88@yahoo.com. Thank's.
 
I am am using the 877A to digitise an audio signal,i want to sample it at 8khz and the then send it over a serial SPI interface to a DAC.I am having major issues with the timing,If i use a 1Mhz crystal and Tad of 4us (which is the max I think one can take)...ill get a rate of about 14k..is it ok?
Following is the code...

void main ()
{
Spi_Init(); // initilalise SPI (built in function) clock is Fosc/4
TRISA =0xFF; // Configure RA0 as analog input
TRISC=0;
ADCON1=0x4F; //configure analog channel An0 and left justified
ADCON0=0x01; // configure a/d clock=fosc/4,powerup a/d
do{
delay_us(20); // acquistion delay
ADCON0.GO_DONE =1; // start conversion;
while (ADCON0.GO_DONE == 1);
Spi_Write(ADRESH);
}
while(1); // infinite loop
}


I simulated it in Proteus ISIS Professional (i haven yet implemented it on hardwre) and during simulation there was excessive load on the CPU,ie; it wasnt able to perform in real time.What could be the reason..need some help urgently..
 
For a start don't cripple it with a 1MHz crystal!. It would also be much faster to use an R2R ladder D2A, you're wasting time sending it as SPI - not writing it using C would probably help as well?.

Are you low pass filtering the input and output?, good sharp filters, at less than 4KHz, to avoid antialiasing.
 
Well actually i have to use SPI as i need to send the a/d result to an ISM transceiver MC13192 from freescale..i was just using the DAC to see if the SPI works..(they dont have transciever on ISIS).Would a 4Mhz crystal be fine...what rate should i set for the SPI clock if i wish to sample at 8Khz?
In some examples I have seen them use the Timer0 to generate an interrupt every 125us(8Khz) for A/d sampling....is this a good method?
 
4MHz would be better, but why not just use 20MHz?, gives you more headroom, particularly as you're using a high level compiler.

I don't see as your SPI clock rate has any bearing on the sample rate?, and you could certainly use timer interrupts to time the sampling if you wanted? - but bear in mind TMR0 is the poorest of the timers, TMR2 would be a lot better.
 
Need some help with the timer settings...I know that it increments every instruction cycle (Tosc x 4) but I cant figure out what the pre-scaler and post scaler do...what do the ratios mean?
 
sohaib_a said:
Need some help with the timer settings...I know that it increments every instruction cycle (Tosc x 4) but I cant figure out what the pre-scaler and post scaler do...what do the ratios mean?
OK, here goes... If anyone sees errors in my explanation, feel free to jump in.

Fosc is your clock, or crystal speed. The timer gets that clock divided by four. So if you have a 20MHz crystal, then Fosc/4 = 5MHz, or 5,000,000 cycles per second.

With a 1:1 prescale, the timer increments once per Fosc/4. We'll call Fosc/4 "clock" from now on.

With a 1:16 prescale, the timer increments once every 16 clocks. With a 1:256 prescale, the timer increments once every 256 clocks. You get the idea, I'm sure. Those bigger prescales give longer timer periods between interrupts.

Then with a 1:1 postscale, every time the timer rolls over it triggers an interrupt.

With a 1:16 postscale, an interrupt isn't triggered until 16 rollovers. This again makes the timer period longer between interrupts.

Just in case you don't understand what I mean by rollover, here it is: The timer is an 8 bit register or a pair of 8 bit registers forming a 16 bit register. An 8 bit timer counts up to 255 ($ff), rolls over to 0 and triggers an interrupt as it rolls over. Then it starts counting up again. A 16 bit timer counts up to 65535 ($ffff) and rolls over to 0 as it triggers an interrupt.

With some scratch paper and a calculator you can calculate the timer periods very accurately. At first it'll seem very difficult, but you'll soon catch on to how to figure it.

Then you can do stuff like set the timer value to the number that gives you the timer period you need. In your interrupt service routine you just reset it to that value every time it rolls over. Or you can have the value vary according to the time period you need, like when using a timer to generate a variable pulse train for a servo.

Oh ya, some timers can use multiple different clock sources too. You have to choose how you want your timer clocked when you set up.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top