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 CCS Technical Support

D/A analog output
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

D/A analog output
PostPosted: Tue Jul 13, 2004 8:04 am     Reply with quote

I need to out put analog signal on one of the pins of 16f877a, how to do that?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Tue Jul 13, 2004 8:06 am     Reply with quote

Google for "PWM" and "PIC" together. Otherwise you need to add a DAC to your circuit.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Jul 13, 2004 8:40 am     Reply with quote

Thank you:
As you said, I already google the internet for sample program and tutorials and circuits by using PWM, does anybody has these already or know some place to go.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Tue Jul 13, 2004 9:55 am     Reply with quote

There is one with all the other CCS example programs.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Jul 13, 2004 9:58 am     Reply with quote

where is it?

Thanks
valemike
Guest







PostPosted: Tue Jul 13, 2004 10:28 am     Reply with quote

Look at Microchip's application notes for "Tips N' Tricks"
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Jul 13, 2004 11:48 am     Reply with quote

I may ask too much, but , are there any specific sample program for me to look? sorry, that is a newbie's question!
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

Which type of output do you need?
PostPosted: Tue Jul 13, 2004 12:29 pm     Reply with quote

What do you want? PWM or true analog output?

If it is analog you must use an external DAC and the one you choose will determine what code is needed whether it is SPI, I2C or parallel etc.

If you want PWM there is lots of PWM code on this site all you have to do is search....
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Tue Jul 13, 2004 12:53 pm     Reply with quote

young wrote:
where is it?

Thanks


The on-line help for CCS has an entry for example / sample programs. There they explain what each one does. They should have been installed in the same directory tree as your compiler.

The CCS website has some additional information about example programs.

Google is filthy with examples on how PWM works (although not all are PIC specific). The Microchip web page search will give you several hits if you search it for "PWM". This fourm will give you several hits if you search it for "PWM". The CCS on-line help will give you a few hits if you search it for "PWM".

I understand that you are a "newbie" but you will find that most people here would rather give you a hint and a shove in the right direction rather than try and write your code for you. Mostly because we know (from past and sometimes painful) experience you learn more doing it yourself.

Your extra-credit homework for today is to find out what "RTFM" stands for... Wink And for a few more points, learn how to use the advanced search features in Google, both these things will carry you a very long way. Very Happy
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Jul 13, 2004 1:09 pm     Reply with quote

Thank you Rob and dyeatman:
I already wrote a PWM short program after all these painfull work..., no painful, exactly, I like these work, by talking wth you guys and get hints help me to think, and finally get solutions, at last, it is appreciation!

At the begining, I am looking for an analog output, and by getting direction, I nearly reach one solution to use pwm to output a PWM signal, but how to change this PWM to analog, this is my first question, the second, if I need real analog signal, I have to use a DAC right? so what kinds of convert is good selection?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PWM to analog output
PostPosted: Tue Jul 13, 2004 1:38 pm     Reply with quote

It depends on how accurate you need the analog output to be. If it doesn't have to be real accurate you can use an integrator circuit on the PWM output to convert the pulse to an averaged voltage.

The integrator circuit consists of basically a resistor on the PWM output pin followed by a capacitor.

What are you going to use the output for? How accurate and stable does the analog volatge have to be?

The answers to these questions will determine what values are needed, or if this method will work, or a DAc is needed....
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Jul 13, 2004 1:51 pm     Reply with quote

Thank you dyeatman:
I am going to control the power of lighting and make dimming effect, I guess a 0.05-0.01 voltage resoultion is good.

I would be glad to test both way, using PWM and DAC. arew their any such circuit I could have a look?
valemike
Guest







PostPosted: Tue Jul 13, 2004 2:14 pm     Reply with quote

I can't believe i looked for this! Embarassed

Look at National Semiconductor's LM331.

It is a frequency to voltage converter. Shoot out any PWM frequency, and you'll see the voltage output go up and down from 0 to Vcc. No ripple either.

Doesn't cost too much to buy the components at Digikey.
-Mike
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Jul 13, 2004 3:04 pm     Reply with quote

young wrote:
Thank you dyeatman:
I am going to control the power of lighting and make dimming effect, I guess a 0.05-0.01 voltage resoultion is good.

I would be glad to test both way, using PWM and DAC. arew their any such circuit I could have a look?


For dimming room lighting you can probably make do with 16 levels. 64 levels will certainly be enough for any human eye. If it is some photographic or scientific use you might have to use more that 8 bits. If you keep your PWM frequency well above the 60Hz (50Hz) line frequency you won't "see" any effect of the PWM noise.
_________________
The search for better is endless. Instead simply find very good and get the job done.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Tue Jul 13, 2004 4:09 pm     Reply with quote

young wrote:
At the begining, I am looking for an analog output, and by getting direction, I nearly reach one solution to use pwm to output a PWM signal, but how to change this PWM to analog, this is my first question, the second, if I need real analog signal, I have to use a DAC right? so what kinds of convert is good selection?


You could benefit from reading "The Art of Electronics" by Horowitz and Hill. Check amazon.com for a used 2nd edition. It is getting a little dated but the fundamentals never change.

Changing a PWM to a DC level requires a low pass filter. The filter can be as simple as a single RC time constant. You can get pretty decent results with a Sallen and Key single op-amp configuration.

You mention you are wanting to dim lights. Are these DC or AC? How are you planning to chop the power? If you are going to use a triac (AC lights) then PWM may not be the simplest. You may want to look at a zero-crossing detection scheme where you delay turn on of the triac based on a delay from the AC line zero crossing. Simple to do but has limitations. In some countries, the regulating authorities frown on this method as it tends to spray EMI.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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