New to mikroE C

geko

Joined Sep 18, 2008
9
If the O/P is still using the 16F88 they mentioned at the beginning of this thread, it doesn't have a internal voltage reference for the ADC.
 

THE_RB

Joined Feb 11, 2008
5,438
My mistake! :eek:

Rif@@ I thought you were using the 40-pin PIC that comes with the EasyPIC7 dev board. That one has the internal ADC reference. :)
 

t06afre

Joined May 11, 2009
5,934
My mistake! :eek:

Rif@@ I thought you were using the 40-pin PIC that comes with the EasyPIC7 dev board. That one has the internal ADC reference. :)
But can that reference be used as an ADC reference? For some time ago I looked at at a new PIC with internal reference. It turned out that the reference could be internally connected to a ADC channel and read. But not used as a reference for the ADC. Have they changed this in this IC? It is hard to keep track on every new PIC. So that is why I am asking
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
I am using 16F88 for now.

Tell me please what is better, the internal reference or the Vdd ?
 

THE_RB

Joined Feb 11, 2008
5,438
But can that reference be used as an ADC reference? For some time ago I looked at at a new PIC with internal reference. It turned out that the reference could be internally connected to a ADC channel and read. But not used as a reference for the ADC. Have they changed this in this IC? It is hard to keep track on every new PIC. So that is why I am asking
I just had to go and boot up my other computer and check the datasheet.

The PIC is the 18F45K22. The internal reference is the FVR module. It can select 1.024, 2.048 or 4.096v reference.

It can then be selected to connect to;
* ADC input
* ADC +Vref (yay!)
* comparator + input
* DAC module

I really don't use that PIC much but it is a very nice one. And 5v/3.3v operation too. :)


Rif@@ said:
Tell me please what is better, the internal reference or the Vdd ?
The 16F88 only has a comparator Vref module, and the datasheet says it is derived from Vdd so will not be more accurate than Vdd.

My experience with the PIC ADC and a 7805 is that the 7805 makes a good stable voltage provided the load current from the 7805 is stable. Generally if your 7805 is only supplying the PIC and display, they draw a stable current and the voltage regulation will be good enough.

BUT, it looks like the entire purpose of this application is to be a voltmeter readout to 0.01v resolution, so you might want to consider a 3-pin voltage reference IC. You can buy a 4.096v external Vref IC for a couple of bucks. That will give you better accuracy for your instrumentation application.
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
I can use a 7805 trimmed to 5V exactly, right ?

The ground pin can be varied a bit to give out 5.00V. No?
 

THE_RB

Joined Feb 11, 2008
5,438
You can calbrate in software, no need to trim the 7805 voltage.

Just assemble the device, test it in comparison to your multimeter, and tweak the software value until it matches your multimeter.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
I updated the program.
I thought I needed a way to shut off the output in case of overload even though there will be current limit.
Since the supply can supply 10A for short periods I thought it's better to shut off if it goes to 10A for some issue the uC can shut off the load.

I managed to switch of the output relay when the current is maxed and turn it on by bringing the Voltage setting to 0V.
So far it works.

I like to know is there any way that a part of program can be disabled from executing when say like ADC value is at 1023 and start when the value goes below

Or can a sub routine be looped continuously until the value is below 1023.

The if statement is not working that way. after "if" it continues and I am confused a bit on how to do tht.

I need advice. Please
 

THE_RB

Joined Feb 11, 2008
5,438
Sorry Rif@@ I'm not understanding what you are asking.

This situation is a good example of the need to write out a flowchart of the device operation. It has grown large enough and complex enough that you are finding it difficult to keep adding stuff and getting it all to work together.

I suggest you grab a pen and paper, and draw out a flowchart of the total operation.

Once you have decided what controls what, and when it does it, the code writing part gets a lot easier.
:)
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
Example.

Say I want to loop a part like power on switch. The routine should only exit and continue to other part of the code if the power relay control port is high. As long as the output relay is off other part of the code should not execute.

This was done by btfss and btfcs in assembly.

Thing is I don't know what I should do in mikroC.
I thought "if" statements can do tht but I was wrong.
Does "else" has to be used after "if" to do that

This program is not big, I have plenty of space.
 

jjw

Joined Dec 24, 2013
823
If I understand this right, you want to read some input port pin and based on its state execute some code or other ?

For example this should work:

Rich (BB code):
if (PORTA.b0==0)
{
     code1
}
else
{ 
    code2
}
or do you want to loop in the first code until port pin goes high ?

Rich (BB code):
while ( PORTA.b0==0)
{ 
    code1
}

code2
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
Later is correct.

I like to loop in power on switch state until the power pin which can control a relay to power up the circuit is high.

After power output pin is active the rest of the code should execute. If the power pin is low I like the code to stay there.

I read a lot of stuff and got my head around the
"while ( look for port high or low)
{power on code}

Rest of the code;
}

something like tht. Will it work.
Do I need to be in ISR. cause the power switch can be pushed any time u know.
Or in the void main().
 

THE_RB

Joined Feb 11, 2008
5,438
A flowchart really helps because you can decide the sequence of events, and "what controls what", before you get stuck in the code.

You can just write the flowcharts as text if you want. Like this;

1. while power pin is low, stay here
2. now power pin went high, loop through these 3 tasks;
2a. test ADC
2b. display ADC result on LCD
2c. check power pin, if low again then go back to 1 (if not, go to 2a)

I find it easier to rough out the flowchart on a piece of paper because you can draw arrows showing where the operation goes to next. That helps to nut out the general flow and improve the flow efficiency.

Flowcharts are your friend! Especially when a project gets larger. :)
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
See the attached file

This is what is working perfectly now.

Do you need more details.

I like add two features but still no luck :(
 

Attachments

THE_RB

Joined Feb 11, 2008
5,438
That's a good start. You need to expand the last box of the flowchart, it's doing a lot of stuff inside one box. :)

It seems to be a protection process. I would think of it in terms of "modes", ie "run mode" and "overcurrent mode".

There are different ways to handle that but one easy way would be to use a variable for mode, then after measuring voltage and current you branch to do two different things (depending which mode it is in).

So if run mode you measure voltage and current and put (or leave) the relay on.

If in overcurrent mode you measure voltage and current, and make sure it meets your safety requirements before you can turn the relay back on.

What are the two features you would like to add?
 
Top