PIC16877A Automatic DC source

Thread Starter

creaver31

Joined Feb 2, 2012
65
Hi,

I am trying to make a automatic DC source, 60s for 0.8V while 90s for 0.25V. I am using PIC16877A, I am also using MikroC. Please help me with the codes. I am using these codes for mg TGS203 project (CO sensor). I am thinking of using a square wave, but how should I do it?

Thanks :)
 

Attachments

THE_RB

Joined Feb 11, 2008
5,438
What have you done so far?

All you have posted is a request for help but you do not show a schematic or any of your code. Please show those.
:)
 

spinnaker

Joined Oct 29, 2009
7,830
What have you done so far?

All you have posted is a request for help but you do not show a schematic or any of your code. Please show those.
:)
Does the post make sense to you? Best I can figure is the OP want to do PWM? And that is only a guess based on the picture posted.
 

spinnaker

Joined Oct 29, 2009
7,830
Is that 60 seconds low pulse and a 90 second high pulse? It would really help if you more clearly define you needs.


PWM is not rocket science. A simple delay will do. (actually 2) What compiler are you using?

The harder part will be the voltages that you require. .25 as your low and .80 as your high I would assume? I don't have the datasheet in front of me but if I had to guess I would say the PIC16877A is a 5V Pic? So you would need some kind of level shifting circuit. I don't think you would be able to do that with the Pic alone. THE_RB might be able to help you there. In fact poke around on his site. He has a lot of great information out there.
 

Thread Starter

creaver31

Joined Feb 2, 2012
65
Yes it's .25 as low and .80 as high and I'm using mikroC. Yup that's my problem, I can't seem to find a way to make those precise outputs with PIC alone, i guess i need to use clamping circuits.
Thanks :)
 

spinnaker

Joined Oct 29, 2009
7,830
Yes it's .25 as low and .80 as high and I'm using mikroC. Yup that's my problem, I can't seem to find a way to make those precise outputs with PIC alone, i guess i need to use clamping circuits.
Thanks :)
If you want precise time then you will want to use a timer interrupt. That would probably give you the most precise delay since it is based directly off of your clock. But with that length of duty cycle it is going to be difficult to be precise. You will not have the resolution on the timer to have a 60 second delay let alone a 90. You will need some type of counter. That takes code and code takes up time.

Your chip might also have a PWM peripheral. That would also be a precise way to generate a PWM but not certain you would be able to do the duty cycle length that you need.

Delay can be used. A lot easier to implement but delay is based off of executing instructions which is an indirect function of your clock.

But I find it very hard to believe that with a 60/90 second PWM, the duty cycle needs to be that precise.

So look up the delay function for mickroC and look up interrupts ad decide how you want to go.


Here is a good tutorial that covers a number of options mentioned:

http://www.mikroe.com/products/view/285/book-pic-microcontrollers-programming-in-c/
 

spinnaker

Joined Oct 29, 2009
7,830
Not sure if I should be adding this since the OP has not attached a schematic but I was giving this project some thought today. With that long of a duty cycle you will want to use an interrupt. A delay would tie up your pic for too long. Unless of course that is all the pic is going to do, then again you might as well use a 555 timer.

THE_RB, can you get that long of a duty cycle with the 555?
 

ErnieM

Joined Apr 24, 2011
8,377
Yes it's .25 as low and .80 as high and I'm using mikroC. Yup that's my problem, I can't seem to find a way to make those precise outputs with PIC alone, i guess i need to use clamping circuits.
Thanks :)
Basically that's what the people here are asking you: what is the circuit the PIC is controlling? All a micro can do is give you signals to turn things on and off, you need to provide these things that get switched.

Saying .25 and .80 volts also does not say much. How do you make the voltage? How much current will these output? How do the get switched?

In any controller project, the "codes" is the last thing to do. The up front work is designing a circuit to cover the needs (specification).

I suggest you back up and start figuring out the circuit (people here can and will help), then the codes can follow. For something like this the program is a trivial thing for anyone with any experience (so a newbie should get past the minefield in under a week).

Good luck and don't get discouraged.
 

Thread Starter

creaver31

Joined Feb 2, 2012
65
Actually, I am controlling a TGS203 Carbon Monoxide detector, and 0.25V and 0.8V are part of requirements for an accurate result. I've attached the specs for the said sensor and also the codes for displaying the result to a LCD display. I don't know what part of the code I should change or remove because I think there are codes there that are not needed. But I want to focus first on the supplies (o.8V and 0.25V) because I want an accurate result. :D
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
Driving the current is probably a simpler solution then making controlled voltage sources.

What source of power do you have in mind?
 

THE_RB

Joined Feb 11, 2008
5,438
I don't open user-generated PDF files, but I had a quick look through your C code.

this looks funky;
mq135Reading = ((ADC_Read(1)/1024.0) * 100.0);

The order of precedence operators () mean that the first operation will get an ADC value between 0-1023 and then divide by 1024.

I understand that you used float math, so it CAN divide a small value by 1024, but MikroC uses 32bit floats and precision will suffer. You would be better off to use an unsigned long, then do the operation like this;
mq135Reading = ((ADC_Read(1)*100) / 1024);

That will be enormously faster and give much better precision. :)

Other than that, you have not initialised your ADC module and setup its pins.

(edit)
spinnaker said:
...
THE_RB, can you get that long of a duty cycle with the 555?
Whoops almost missed that! You can get pretty much any duty cycle with a 555 if you use the right circuit, it might need a diode or two in the cap charge section.

But the 60 sec and 90 sec timing is too long to do well with a 555. And he already has a PIC.

MikroC that the OP is using has inbuilt delay functions, it is trivial to make a 1 second delay like this;
Delay_mS(1000);
And obviously he can repeat that 60 or 90 times as needed. :)
 
Last edited:

Thread Starter

creaver31

Joined Feb 2, 2012
65
MikroC that the OP is using has inbuilt delay functions, it is trivial to make a 1 second delay like this;
Delay_mS(1000);
And obviously he can repeat that 60 or 90 times as needed. :)
Thanks :D.So I can use the delay function, the next problem would be how to have a 0.25 and 0.8 DC source, but the alternative could be 369mA for 60sec and 133mA for 90sec
 
Top