|
|
View previous topic :: View next topic |
Author |
Message |
JBM
Joined: 12 May 2004 Posts: 54 Location: edinburgh, Scotland
|
PIC16F88 comparator |
Posted: Wed Mar 08, 2006 3:03 pm |
|
|
I'm trying to use the PIC16F88's internal comparator, but so far, no joy.
Here's my code:
Code: | #include <16F88.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
void main(void)
{
setup_oscillator(OSC_8MHZ);
setup_comparator(A0_VR_A1_VR); // Comparator mode 2
setup_vref(0xC0 | 9);
while(1){
output_bit(PIN_B5,C1OUT);
delay_ms(100);
}
} |
it should be strikingly similar to the code here, but isn't identical. This is beacuse my version of PCM is about 2 years old (version 3.184), which is likely to be where my problem is.
If that isn't the case, what am I doing wrong? I've got the voltage reference oupoutting fine on A2, but no matter what my voltage on A0 is, C1OUT is always 0.
Any ideas?
-JBM |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 08, 2006 3:28 pm |
|
|
In your version of the compiler, the wrong address is used
for the CMCON register.
Here is the code for your version:
Code: |
... setup_comparator(A0_VR_A1_VR); // Comparator mode 2
0028: MOVLW 02
0029: BCF 03.5 // Bank 0
002A: MOVWF 1F // Wrong address for CMCON
002B: BSF 03.5 // Bank 1
002C: MOVF 05,W // Read TRISA
002D: IORLW 03 // Set A0 and A1 as inputs
002E: MOVWF 05 // Write to TRISA
002F: MOVLW 06 // Do a short delay
0030: MOVWF 77
0031: DECFSZ 77,F
0032: GOTO 031
0033: NOP
0034: BCF 03.5 // Bank 0
0035: MOVF 1F,W // Read the wrong register
0036: BCF 0D.6 // Clear the CMIF bit
|
Here is the code for PCM vs. 3.245:
Code: |
... setup_comparator(A0_VR_A1_VR); // Comparator mode 2
// Note: Bank 1 is already selected.
0027: MOVLW 02
0028: MOVWF 1C // Set CMCON (0x9c) = 0x02
0029: MOVF 05,W // Read TRISA
002A: IORLW 03
002B: MOVWF 05 // Set A0 and A1 = inputws
002C: MOVLW 06 // Do a short delay
002D: MOVWF 77
002E: DECFSZ 77,F
002F: GOTO 02E
0030: NOP
0031: MOVF 1C,W // Read CMCON
0032: BCF 03.5 // Bank 0
0033: BCF 0D.6 // Clear the CMIF bit
|
You could fix this by writing to CMCON directly with a line of code.
Define the address with a #byte statement. |
|
|
JBM
Joined: 12 May 2004 Posts: 54 Location: edinburgh, Scotland
|
|
Posted: Wed Mar 08, 2006 3:30 pm |
|
|
PCM, you never cease to amaze me.
Thanks a million.
-JBM |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|