Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 8th March 2007, 06:24 PM   (permalink)
Default pic16f870 a to d, d to a

I'm pretty new to this stuff but I'm building a program to shift the voltage from one value to another in varying degrees depending on the input voltage range.

.5v shift up to .6
.4v shift up to .45 etc...

I think I've got the code down for the a to d conversion and then I read the pic has no analog output. Oops!

I've tried looking for an IC to convert d to a but i don't really know what I'm looing for or how to interface it with the pic16f870 in software or hardware.
I've spent a lot of time just getting to here!
hotrodhed120 is offline  
Old 8th March 2007, 06:46 PM   (permalink)
Default

Quote:
Originally Posted by hotrodhed120
I'm pretty new to this stuff but I'm building a program to shift the voltage from one value to another in varying degrees depending on the input voltage range.

.5v shift up to .6
.4v shift up to .45 etc...

I think I've got the code down for the a to d conversion and then I read the pic has no analog output. Oops!

I've tried looking for an IC to convert d to a but i don't really know what I'm looing for or how to interface it with the pic16f870 in software or hardware.
I've spent a lot of time just getting to here!
microchip makes a few DtoA converters
but this link shows how to do it with a controller,
http://ww1.microchip.com/downloads/e...tes/00655a.pdf
this is their d/a line
http://www.microchip.com/ParamChartS...branchID=11028
williB is offline  
Old 8th March 2007, 07:19 PM   (permalink)
Default

Quote:
Originally Posted by hotrodhed120
I'm pretty new to this stuff but I'm building a program to shift the voltage from one value to another in varying degrees depending on the input voltage range.

.5v shift up to .6
.4v shift up to .45 etc...

I think I've got the code down for the a to d conversion and then I read the pic has no analog output. Oops!

I've tried looking for an IC to convert d to a but i don't really know what I'm looing for or how to interface it with the pic16f870 in software or hardware.
I've spent a lot of time just getting to here!
A simple (and cheap) method is an 'R2R ladder', this just requires resistors and an opamp buffer to give a nice fast D2A output - no need for a special IC, and it's really fast as well. MicroChip have an application note about it at http://www.microchip.com/stellent/id...pnote=en011071
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2007, 07:41 PM   (permalink)
Default

I was hoping to use code to add a value to an almost infinitly variable voltage between 0v-1v, if i read these app. notes right I'll only have a limited amount of step voltages, one for each output. I don't know if pwm will work, because the output analog signal will be monitored by a separate computer that I have no control over. I would like to use this application to modify the signal before the main computer even sees it. PWM is still a grey area for me in actual implementation.
hotrodhed120 is offline  
Old 8th March 2007, 07:45 PM   (permalink)
Default

Is there maybe a circuit that uses PWM to vary a voltage fairly quickly using opamp or mosfets?
hotrodhed120 is offline  
Old 8th March 2007, 07:47 PM   (permalink)
Default

Quote:
Originally Posted by hotrodhed120
I was hoping to use code to add a value to an almost infinitly variable voltage between 0v-1v, if i read these app. notes right I'll only have a limited amount of step voltages, one for each output. I don't know if pwm will work, because the output analog signal will be monitored by a separate computer that I have no control over. I would like to use this application to modify the signal before the main computer even sees it. PWM is still a grey area for me in actual implementation.


Sorry, not infinite just 0-255 which would be great.
hotrodhed120 is offline  
Old 8th March 2007, 08:15 PM   (permalink)
Default

Quote:
Originally Posted by hotrodhed120
Sorry, not infinite just 0-255 which would be great.
An R2R ladder would be great for 8 bit (0-255), although you can make it as high a resolution as you need - but 8 bit uses a single port, and the higher resolution you have, the smaller the tolerance of the resistors has to be.

R2R is dead easy to program, because you just stick the value out the port, and there's no filtering required as with PWM - with PWM the response time depends on the filtering, with fast PWM and higher frequency filters being required for a fast response time (check the MicroChip link I posted, which shows both R2R and PWM).
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2007, 08:32 PM   (permalink)
Default

I gotcha, so portb would have output bits 0-7 set to 00110101 to equal 53 (in fig. 4)to get the desired output from the r2r? that would work great! thanks!
hotrodhed120 is offline  
Old 8th March 2007, 08:38 PM   (permalink)
Default

Quote:
Originally Posted by hotrodhed120
I gotcha, so portb would have output bits 0-7 set to 00110101 to equal 53 (in fig. 4)to get the desired output from the r2r? that would work great! thanks!
Like I said, it's REALLY easy!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th March 2007, 10:50 PM   (permalink)
Default

The hard part seems to find one. I've got a P# 898-81-r10k from BI Tech but cannot find a supplier with one. Help!
hotrodhed120 is offline  
Old 9th March 2007, 07:27 AM   (permalink)
Default

Quote:
Originally Posted by hotrodhed120
The hard part seems to find one. I've got a P# 898-81-r10k from BI Tech but cannot find a supplier with one. Help!
It's just resistors, you only need to buy resistors - that's what makes it so easy - use at least 1% ones, preferably better.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 9th March 2007, 08:40 AM   (permalink)
Default

Geez, you got the right chip for the job, so use it!

I made this program in Proton+ but I don’t think the lite version supports 16F870 - grab a 16F877 so you can develop code in the lite version. Pretty much the same, just that it has more pins..

anyhow, use the ADC feature to sample the input voltage, then use the PWM feature of the PIC to make an analogue output whos value will be the same as the input.

This is just an example of how to use the ADC and PWM features, its not a specific answer, but should save you alot of board space and components..

The input voltage can be anything from 0-5V and the output is a 255 Bit (0.019V steps) output

Watch the program in action ( a 4 way dip was used to supply different voltages ) <<< Video >>>

Heres the program;


Code:
Device = 16F870

XTAL = 4

Declare ADIN_RES 10 		' 10-bit result required 
Declare ADIN_TAD FRC 		' RC OSC chosen 
Declare ADIN_STIME 50 		' Allow 50us sample time 

Declare CCP1_PIN = PORTC.2

Dim Result as Float
Dim Total as Float
Dim X as Byte

ADCON1 = %10000000 			' Set analogue inputs, Vref is Vdd

Main:
	 Total = 0
	 X = 0
	 
	 Repeat 
	 		Result = ADIN 0
	 		Total = Total + Result
	 		Inc X
	 Until X = 10
	 
	 Result = Total / 10
	 
	 Result = Result / 1023 * 255
	 
	 X = Result
	 
	 If X = 255 Then X = 254
	 
	 HPWM 1, X, 32767

	 Goto Main
Just to explain a couple of things;

* I generally take multiple samples (this case 10) to get a more accurate result of the ADC, just divided the total by 10 to find the average

* I move Result into X because the HPWM function only supports 16bit math opperations (don't worry about thinking too far into this at the moment) and I check if X is >= 255 as the PWM output will be ambiguous.. (something you learn after playing with it after a while)

* PWM is not a hard concept to tackle, for the beginner it has limited uses, but this is an example of how to use it for DAC (Digital to analogue conversions). For more info on it, have a look here

* Have a read in the Proton help file for more info on specific commands! And see what else you can do while your there!
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 9th March 2007 at 08:54 AM.
gramo is offline  
Old 9th March 2007, 08:56 AM   (permalink)
Default

Just on that, I have made the program more accurate.

The only step it cant reach is 255 (because the HPWM output become ambigous)

I modified this line

Code:
If X = 255 Then X = 254
To

Code:
If X >= 254 Then X = 253

Inc X

And this moved the output scale up by one, making it more accurate (you might have notice the output was slightly less on the first example) - Have a look at this video >>> Video <<<


Hope this helps you/someone else out!
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 9th March 2007 at 09:03 AM.
gramo is offline  
Old 9th March 2007, 09:27 AM   (permalink)
Default

Quote:
Originally Posted by gramo
Just on that, I have made the program more accurate.

The only step it cant reach is 255 (because the HPWM output become ambigous)
I don't see your problem?, setting the PWM to 255 (for 8 bit PWM) sets the output at 5V (no pulses) just as you want, just as setting it to 0 outputs zero volts (no pulses). I also don't see how your modification makes it more accurate?, it makes it less accurate!.

The problem with PWM though is the response time, which to be any good needs more complicated filtering than your example - and will never approach the speed of an R2R ladder.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 9th March 2007, 10:25 AM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
I don't see your problem?, setting the PWM to 255 (for 8 bit PWM) sets the output at 5V (no pulses) just as you want, just as setting it to 0 outputs zero volts (no pulses). I also don't see how your modification makes it more accurate?, it makes it less accurate!.
Did you watch the video's? Its fairly clear that the first program was one step out.


Quote:
Originally Posted by Nigel Goodwin
The problem with PWM though is the response time, which to be any good needs more complicated filtering than your example - and will never approach the speed of an R2R ladder.
Correct, but the response time in this situation is around 50-100ms (average guess) as the videos are the file being simmed at around 1/3rd real-time. Is that good enough for this app? Its great for many apps where uS updates arnt critical. the output can be buffered by an opamp quite easily aswell. You could even through in a bigger cap to slew the output more to give a longer response time if needed

I'm not sure as to why the PWM is ambiguous at 255, perhaps its my outdated version of Proton+ but watch this video of the following code

Code:
Device = 16F877
Declare XTAL = 4

Declare CCP1_PIN = PORTC.2

HPWM 1, 255, 32767

While 1=1 

Wend
32767 is the frequency, 1 is the channel, 255 is the setting for PWM duty cycle. Like you said - 255 should give a straight 5V - for some reason I can't get it to do that, the following video displays a couple of different PWM's 128 (50%), 192 (75%), 254 (99%), 255 (100%) each for a couple of seconds on a cro, but take a look at the 255, its anything but stable.. its anything but a steady 5V.. any ideas?

EDIT: forgot to link the video, click here for it
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 9th March 2007 at 10:31 AM.
gramo is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
pc to pic16f870 serial communication nikos23 Micro Controllers 5 16th January 2006 04:04 AM
PIC16F870 tinky Micro Controllers 6 1st September 2005 07:25 AM
Impulse on ADC PIC16F870 sardineta Micro Controllers 0 7th January 2005 05:14 PM
characteristics and apps: PIC16F870 sardineta Micro Controllers 76 4th January 2005 08:33 PM



All times are GMT. The time now is 07:28 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker