![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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! | |
| |
| | (permalink) | |
| Quote:
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 | ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| Is there maybe a circuit that uses PWM to vary a voltage fairly quickly using opamp or mosfets? | |
| |
| | (permalink) | |
| Quote:
Sorry, not infinite just 0-255 which would be great. | ||
| |
| | (permalink) | |
| Quote:
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). | ||
| |
| | (permalink) |
| 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! | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| 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! | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| 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 * 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. | |
| |
| | (permalink) |
| 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 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. | |
| |
| | (permalink) | |
| Quote:
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. | ||
| |
| | (permalink) | ||
| Quote:
Quote:
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 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. | |||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |