1 Attachment(s)
what is wrong in this code
i want to light the led at portb.0 when the output of comparator is high and to light led at portb.1 when comparator output is low, my code compiled successful and on running this code light a ked at portb.1 always without depending on the output of the copmarator, the output of the comparator doesn't depend on the inputs...what is wrong hear
this is my code and i attach my circuit
Code:
C10UT VAR CMCON.6
ADCON1=7
CMCON=2
PORTB=%00000000
TRISB=%00000000
lop:
if c10ut=1 then
portb.0=1
else
portb.1=1
endif
goto lop
end
1 Attachment(s)
Re: what is wrong in this code
Code:
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _BODEN_OFF & _LVP_OFF & _CP_ON
CLEAR
TRISA = 255
TRISB = 0
' Comparator Control
CMCON=100101
CompOut var CMCON.7
' CM7 C2OUT Comparator Output 2 (Read Only)
' CM6 C1OUT Comparator Output 1 (Read Only)
' Voltage Reference Control
VRCON = 0
Pauseus 10 ' VREF to settle.
PORTB = 0
LED_A var PORTB.0
LED_B var PORTB.6
Start:
led_a = compout
led_B = ~compout
pause 1
goto start
end
Attachment 6330
what is wrong in this code
i want to light the led at portb.0 when the output of comparator is high and to light led at portb.1 when comparator output is low, my code compiled successful and on running this code light a ked at portb.1 always without depending on the output of the copmarator, the output of the comparator doesn't depend on the inputs...what is wrong hear
this is my code
Code:
C10UT VAR CMCON.6
ADCON1=7
CMCON=2
PORTB=000000
TRISB=000000
lop:
if c10ut=1 then
portb.0=1
else
portb.1=1
endif
goto lop
end
Re: what is wrong in this code
When C1Out is 1 you set PortB.0 HIGH and when C1Out is 0 you set PortB.1 HIGH. But there is no code in the loop to set either of the outputs LOW again.
Code:
lop:
if C1Out = 1 THEN
PortB.0 = 1 ' One on
PortB.1 = 0 ' The other off
ELSE
PortB.0 = 0 ' On off
PortB.1 = 1 ' The other on
ENDIF
GOTO lop
Re: what is wrong in this code
Quote:
Originally Posted by
HenrikOlsson
When C1Out is 1 you set PortB.0 HIGH and when C1Out is 0 you set PortB.1 HIGH. But there is no code in the loop to set
either of the outputs LOW again.
Code:
lop:
if C1Out = 1 THEN
PortB.0 = 1 ' One on
PortB.1 = 0 ' The other off
ELSE
PortB.0 = 0 ' On off
PortB.1 = 1 ' The other on
ENDIF
GOTO lop
yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance
Re: what is wrong in this code
Quote:
Originally Posted by
chitalula
yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance
sayzer i tried to run your but it didn't do anything, i don't know why. and i need a comparison in my code can you add too?
Re: what is wrong in this code
Quote:
yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance
I already DID just that. The code in my previous message IS edited so it should work the way I think you want.
Re: what is wrong in this code
Quote:
Originally Posted by
HenrikOlsson
I already DID just that. The code in my previous message IS edited so it should work the way I think you want.
i tried to do as you told me but it didn't work as i want, led at portb.1 is always on even if the voltages at RA0 pin is changed. it seems the comparison is not working on the if statement, still have a problem.
thanx in advance
Re: what is wrong in this code
The code and the circuit in my post works with no problem in simulation.
Re: what is wrong in this code
Quote:
Originally Posted by
chitalula
yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance
thanx for your suggestion. on stimulation if the input voltage equal to vref else statement always and if the input voltage is higher than or less than Vref else statement is executed too. it seems the "if statement" is not functioning, have you any solution on that case, i have no way to go forward , help me please
Re: what is wrong in this code
I'm pretty sure that the IF statement executes as it should. The problem is likely that the C1Out doesn't actually toggle.
According to your schematic in the first post you have one input to RA0 and the other to RA2. As far as I can see in the datasheet, section 12.1, the inputs to comparator 1 is RA0 and RA3.
/Henrik.
Re: what is wrong in this code
Thanx alot henrikolsson and sayzer for all of your suggestions, the problem was in configuration of cmcon, now it work as i want, thanx in advance
Re: what is wrong in this code
How can it work when the two inputs, according to your schematic, are wired to two different comparators? What did you change CMCON to to make it work?
Re: what is wrong in this code
Quote:
Originally Posted by
HenrikOlsson
How can it work when the two inputs, according to your schematic, are wired to two different comparators? What did you change CMCON to to make it work?
HenrikOsson my big problem was in CMCON register configuration, i leave my previous circuit and i took the circuit uploaded by sayzer. and i edit some code there by puting my own code