PDA

View Full Version : need a pic basic program



asifiqbal
- 15th March 2014, 08:59
hello everyone
I need this simple program please someone help me,
I have b.0 as inputpin and b.1 as output ,
I want if input increases then output volt which is 5 volt dc should decrease with 1:1 relation but reverse order,for example if my input is
0 percent then output should be 100 percent and if
input is 10 %then output should be 90 %
if input is 55 %then output should be 45 %
i hope i have explained my requirement clearly ,thanks

khoog
- 15th March 2014, 15:16
And how much will you pay the first person who does this work for you?

AvionicsMaster1
- 15th March 2014, 16:06
I think you've explained it quite clearly.

First, you need to go to the Microchip site and download the datasheet for the specific chip you're using. Read through it noting what registers if any need to be set for the chip to work.

I'd then recommend you search this forum for simple programs to blink and LED on pin b.1 to ensure you're communicating with the chip.

Then, search this forum for PWM, Pulse Width Modulation, and use those posts to write your own code.

Once that's done post your code and your schematic along with chip number, PBP version and most everyone here will help you to "fix" your errors.

I look forward to hearing from you.

andywpg
- 15th March 2014, 17:15
I think you've explained it quite clearly.

First, you need to go to the Microchip site and download the datasheet for the specific chip you're using. Read through it noting what registers if any need to be set for the chip to work.

I'd then recommend you search this forum for simple programs to blink and LED on pin b.1 to ensure you're communicating with the chip.

Then, search this forum for PWM, Pulse Width Modulation, and use those posts to write your own code.

Once that's done post your code and your schematic along with chip number, PBP version and most everyone here will help you to "fix" your errors.

I look forward to hearing from you.

Isn't it funny how people seem to think we all having NOTHING to do of our own, but are just waiting to create their 'dream device' for them for nothing. Heck, I have enough problems creating my own, let alone someone else's!

Demon
- 16th March 2014, 23:26
Just out of curiosity, can't this be done using discrete chips alone?


if input increases then output volt which is 5 volt dc should decrease with 1:1 relation but reverse order

I've only dabbled with gates, transistors and amplifiers; but can't they do this very well?

Robert

Charlie
- 16th March 2014, 23:38
Absolutely, Robert. But that would not be the point of the school project, would it?

richard
- 16th March 2014, 23:51
everyone assumes the input is a pwm stream ,if so what frequency . what if the input is actually an analog level ?
ditto for the output. there not enough info in this question

asifiqbal
- 17th March 2014, 06:05
well i am a student and cant pay anything ,i have to build a project as assighnment ,i have to build a triac and microchip based voltage stablizer, i have a transformer with 0-150-250 volts loops and a triac drives the 150 loop of transformer ,an optocoupler drives the triac ,its input is 0 to 1 volt dc which will be controlled by pic 16f72 outputpin and another inputpin of 16f72 which is attached with transformer's 250 loop which is also a output of stablizer voltage ,it ia attached through a optocoupler ,when voltage will vary from 150 to 250 then microcontroller and triac will adjust is to 220 volt ,I have done all work with electronics circuit the only missing thing is a programm , the only thing i know is how to blink a led with microcontroller , can someone tell me how to use pwm to build my project ,thanks in advance

richard
- 17th March 2014, 06:55
simple pwm is not what you want for a triac regulator , search this forum for light dimmer projects , one of them should give you some ideas

amgen
- 17th March 2014, 11:38
Phase control with feedback has several hardware/software functions that must work together.
I break down each function to its own operation and write the program so each function can be tested separately.... then the main program brings the functions together.
For Phase control you may need.....
-zero cross detector circuit and software (requires interrupts by microprocessor)
-Triac drive function ckt/routine , pulsed or timed pulse for inductive loads (inductive loads can 'bounce triac off at wrong time if gate not held on)
- voltage feedback ckt/routines.....takes some smoothing hardware to get reasonable DC level from the AC voltage.
- a main program loop to combine all the functions, control/on/off, adjust parameters, check and handle errors etc.
Breaking projects down to testable individual parts has been the easiest method to make working stuff for me.
don

thasatelliteguy
- 3rd May 2014, 11:04
Sounds like you need to find a late model Chevrolet throttle position sensor and call it a day!

So...
i don't know if this is the case (I'm actually a lil curious...) Is 5v output as PWM a straight % based on dutycycle? For instance...
5v output @ 50% dutycycle = 2.5v?

cuz if so then set

HPWM dutycycle = ((5-ADCIN0)/5)*255

and ur straight....

Subtract INPUT from 5 to get the inverse
Divide by 5 to get the percentage output you want
multiply the % by 255 because dutycycle is set 0-255

of course, if 50% dutycycle <> 50% voltage, I just wasted the last 7 minutes of my life...