Hi, got a problem hopefully someone can answer for me. (im a noob)
Im trying to use the on-board comparator function of the PIC16f88 and a 3 axis accelerometer (https://www.sparkfun.com/products/9652?) on a project. I am trying to use the comparator function to effectively turn my analog accelerometer into a "switch." the end goal is to have the pic ouput a signal to another pic when the accelerometer is activated a certain amount. For instance you shake the accelerometer in the XY plane and it sets pin 9 high, for example.
Ive got some code that hopefully will give some insight on what im trying to do. the code is assuming I have to take the ouput of CM1 and attach it to another pic for the logic to work. CM1 ouputs on RA3, that is then wired into the portb.0 im using in the code.
Now my question is whether or not the PIC recognizes the value of the comparator output internally or do I have to connect the comparator output to another pin on the pic for the logic to work? Im trying to avoid this so I have more pins to use for other things. also, if anybody has a better idea on how to turn my analog accelerometer into a "switch" for the pic Im obviously open to suggestions.
Im trying to use the on-board comparator function of the PIC16f88 and a 3 axis accelerometer (https://www.sparkfun.com/products/9652?) on a project. I am trying to use the comparator function to effectively turn my analog accelerometer into a "switch." the end goal is to have the pic ouput a signal to another pic when the accelerometer is activated a certain amount. For instance you shake the accelerometer in the XY plane and it sets pin 9 high, for example.
Ive got some code that hopefully will give some insight on what im trying to do. the code is assuming I have to take the ouput of CM1 and attach it to another pic for the logic to work. CM1 ouputs on RA3, that is then wired into the portb.0 im using in the code.
Now my question is whether or not the PIC recognizes the value of the comparator output internally or do I have to connect the comparator output to another pin on the pic for the logic to work? Im trying to avoid this so I have more pins to use for other things. also, if anybody has a better idea on how to turn my analog accelerometer into a "switch" for the pic Im obviously open to suggestions.
Rich (BB code):
define OSC 8
OSCCON.4=1
OSCCON.5=1
OSCCON.6=1
ANSEL = %00000001 'setting 1 pin to analog
TRISA = %00000001
TRISB = %11111111 'defining inputs and outputs for the pic
CMCON = %00000110 'setting the comparator layout (2 multiplexed)
CVRCON = %10000011 ' setting internal Vref to 1.72 volts
pause 1000
LEADLOOP
if portb.0 == 1 then portb.0 = 1; //Showing by clearing LED at RB0
if portb.0 == 0 then portb.0 = 0; //Showing by lighting LED at RB0
goto leadloop
end