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

signal alternative

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



Joined: 16 Apr 2009
Posts: 6

View user's profile Send private message Send e-mail

signal alternative
PostPosted: Tue Apr 21, 2009 2:58 am     Reply with quote

my problem is that I have a alternative signal between
(0 and 5) volts and a frequency of 50hz and I want to convert it into digital signals by the pic 16F877 via a serial link rs 232 but when I retrieve it I see my signal random points on the visual terminal exp: 2.5 0.5 3.85 3.2 1.25 4.36 ...........
while I wish that my signal shows 2.5 2.8 3.2 3.6 3.8 4.2 4.5 4.8 4.3 3.9 3.8 ..........
Here is my program
Code:
#include "C:----------------------------------------------------------"

float courant;
void main()
{

   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_32);
   set_adc_channel(0);
    delay_us(20);
    while(true)
   {
      courant=read_adc();
         
         courant = (courant*5)/1023;
         printf("courant=%f\r",courant);
        }
     

   // TODO: USER CODE!!

}

where is the problem if you enjoy
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Apr 21, 2009 7:01 am     Reply with quote

Can you accurately measure a DC source? Try a 1.5V alkaline cell or a 3V mercury cell. That would remove questions of timing.

Just what does your signal look like? Is it DC with a small AC ripple?
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah
Guest







PostPosted: Tue Apr 21, 2009 7:22 am     Reply with quote

What is your serial baud rate?.
The main limitation on the loop time for the PIC here, will be the time taken to send the data. You are sending potentially perhaps 13 characters each time round the loop. If you are running at 9600bps, then this will take nearly 14mSec. Add the time for the floating point arithmetic (depends on the processor clock, but probably at least another couple of mSec to perform both the original arithmetic, and the divisions needed to print the data), and you will only be taking perhaps 60 samples per second. What you have is exactly what you'd expect if sampling a 50Hz AC waveform, at such a slow interval....

Best Wishes
ADAM75



Joined: 16 Apr 2009
Posts: 6

View user's profile Send private message Send e-mail

signal alternative
PostPosted: Tue Apr 21, 2009 11:50 am     Reply with quote

then it is just after the program I cried[/img]
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Apr 21, 2009 4:37 pm     Reply with quote

a factor that is missing here:

What is the GOAL?

1- a good running average value ?

2- OR an instantaneous value / digitized stream where the samples you collect represent the ac waveform?

3- something else entirely?


#1 can be done with external R-C , or integration as we like to call it.

#2 requires understanding of a HOST of timing issues that you have not begun to get at, and that Tlemah is kindly alluding to in the most gentle of ways.

#3 is blue sky and might be part hardware - might be a higher clock speed pic - or some hardware hybrid design.

presenting us with a clearer goal, the feedback can be more specific and better directed.
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