Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F2550 compatator not working

Status
Not open for further replies.

KVN1477

Junior Member level 3
Joined
Nov 18, 2013
Messages
26
Helped
4
Reputation
8
Reaction score
4
Trophy points
3
Activity points
184
hi all,
i have written simple code to check comparator output, but nothing is happening
i have used micro c pro for pic for writing program
i have disabled PORTB A to D conversion in config bit settings. here is my program
HTML:
void main()
{
osccon=0x7c;    //   select 8Mhz internal oscillator
//CONFIG6H.bit1=0;
//adcon1=0x07;
//porta=0x00;
//trisa=0x0f;
portb=0;
trisb=0;
CMCON=0x02; //two independent comparator
CVRCON=0x00;  // desiable internal ref vtg
delay_ms(50);
while(1)
{
 if(CMCON.c1out==1)
 {portb.f4==1;}
 else
 {portb.f4==0;}
 }
}
plz help
 

Hi,

I don't know this language. In fact, I am learning C at the moment.

However, I looked at your code and this line below caught my interest.
...
while(1)
...


Should it not be?:
Code:
 [B]
...
while([I]<something>[/I] == 1)
...[/B]
 

Hi,

"While (1)" is correct.
It simply describes the unconditional (because it is always TRUE) main loop.

You may find this expression in almost any C# code.

Klaus
 

Hi,

I don't know this language. In fact, I am learning C at the moment.

However, I looked at your code and this line below caught my interest.



Should it not be?:
Code:
 [B]
...
while([I]<something>[/I] == 1)
...[/B]

that is an infinite loop
 

...
"While (1)" is correct.
It simply describes the unconditional (because it is always TRUE) main loop.
...

This means the loop is always executed?
 

Hi,

This means the loop is always executed?
Yes, that´s what a main loop is supposed to do.

Klaus
 

Thanks Klaus.

I think there is something I'm not aware of:

Like I mentioned earlier, I'm learning C programming. For MCU's I'm I supposed to be limited to a particular subset of C?
 

Hi Akanimo.

For further discussions please start a new thread, because this doesn´t belong to the OP´s problem.

Klaus
 

For a start you should write digital output to the LAT registers. This avoids the RMW problem: that is not likely to be affecting you in this case, but still it is good practice.
What is actually happening?
Can you toggle the PORTB pin on its own? This is just to check that the output aspect is working as RB4 also carries AN11 although I think you are saying that you have set the PBADEN config setting do this pin defaults to digital mode.
What sort of voltages are you applying to RA0 (AN0) and RA3 (AN3)? How are you varying these to check for a change in the comparator output? WHat is the result?
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top