12F615 comparator programming

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
oookey
Posts: 42
Joined: Thu Mar 08, 2012 3:00 pm
Has thanked: 17 times
Contact:

12F615 comparator programming

Post by oookey »

Hi :D ,

i' m going to try out using the TV remote control as an input signal to the 12F615 and trigger out PWM signal.

Looking at the datasheet of the 12F615, it has the CCP features. Please advice if i could implement it in the following manner (sketch):
Few points i need your expert advice:

1. The signal received is rather weak, further away emits signal weaker signal received at GP0, if i put the remote at 1m (3ft) away, the voltage at GP0 is 0.1V :| , does the raw signal need boot up to 2V< signal volt <5V prior GP0 ?
or could i set the reference voltage at 0.05V? :?:
2. Could i implement compare mode in FC3? How could i do so?

datasheets: photo diode http://www.farnell.com/datasheets/1672048.pdf
12F615 http://ww1.microchip.com/downloads/en/D ... 41302D.pdf
Thanks :)
oookey
Attachments
Compare and PWM.png
(45.18 KiB) Downloaded 10121 times

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: 12F615 comparator programming

Post by Kenrix2 »

You might want to try the Comparator module instead of the CCP for the input, that way you can set the "reference voltage" or I would call it the "trip voltage" (input-) to whatever you want externally. Then have your photo diode connect to the comparator(input+). If (input +)voltage rises to within 5mv of (input-) voltage the comparator output goes high. PIC analog inputs do require an input impedance of less than 10kohms and looking at your drawing you might not be within that spec. Just a thought, maybe a photo transistor or infrared receiver would work better here.

If you want to test the circuit with the comparator drop a "c icon" into your program and copy and paste the following into it:

cr_bit(trisio, TRISIO2);//configure GP2 as an output
st_bit(trisio, TTRISIO0);//configure GP0 as an input
st_bit(trisio, TRISIO1);//configure GP1 as an input
st_bit(ansel, ANS0);//configure GP0 as analog input
st_bit(ansel, ANS1);//configure GP1 as analog input
cmcon1=0b00000000;//no hysteresis, (set bit 3 to turn it on)
cmcon0=0b11110000;//turn on comparator, inverted output to pin GP2 (clear bit 5 to turn off)

These are the pin-outs, GP0 is comparator input+, GP1 is comparator input- , GP2 is comparator output.
After testing you can turn off GP2 comparator output and add your PWM code, since they share the same pin.
I didn't have that chip so I couldn't test it but, I do have it working on other PIC's both 12F and 16F.

oookey
Posts: 42
Joined: Thu Mar 08, 2012 3:00 pm
Has thanked: 17 times
Contact:

Re: 12F615 comparator programming

Post by oookey »

Hi Kenrix2,
Kenrix2 wrote:You might want to try the Comparator module instead of the CCP for the input, that way you can set the "reference voltage" Then have your photo diode connect to the comparator(input+). If (input +)voltage rises to within 5mv of (input-) voltage the comparator output goes high. PIC analog inputs do require an input impedance of less than 10kohms and looking at your drawing you might not be within that spec. Just a thought, maybe a photo transistor or infrared receiver would work better here.
Yah may be i should remove the 1M ohm, but this way the input+ would not able to pull to 0V, when there is no IR signal ?
Kenrix2 wrote: cr_bit(trisio, TRISIO2);//configure GP2 as an output
st_bit(trisio, TTRISIO0);//configure GP0 as an input
st_bit(trisio, TRISIO1);//configure GP1 as an input
st_bit(ansel, ANS0);//configure GP0 as analog input
st_bit(ansel, ANS1);//configure GP1 as analog input
cmcon1=0b00000000;//no hysteresis, (set bit 3 to turn it on)
cmcon0=0b11110000;//turn on comparator, inverted output to pin GP2 (clear bit 5 to turn off)
i need to set internal refer voltage to 50mV, is there a setting to achieve it, as the receiving voltage is about 100mV?
Thanks

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: 12F615 comparator programming

Post by Kenrix2 »

Leave the resistor in and see what the pic does. As for the 50 mv internal, there is no internal. Use a resistor divider from Vdd to gnd and set it to as close to your peak value as possible like 95mv. That is the trip voltage which connects to (input-) GP1. If your photo diode which is connected to (input+) GP0 produces a voltage of at least 95mv, the comparator will make GP2 5volts.

I really think without filtering of noise and some amplification your going to have issues with this project. An infrared receiver takes care of all this for you. You could even read the codes sent by your tv remote and adjust the PWM duty accordingly.

oookey
Posts: 42
Joined: Thu Mar 08, 2012 3:00 pm
Has thanked: 17 times
Contact:

Re: 12F615 comparator programming

Post by oookey »

Hi,
I tried not using the comparator, but simply let the pot GP2 continue loop ON and OFF for 1 sec each, but it did not perform as wanted, it ON and never OFF :?

If I changed start with continue loop OFF and ON for 1 sec each, the pot never turned ON at all :!:
Same when i changed to GP1.

But in simulation it turned ON and OFF.
Please any suggestion.
Attachments
test.fcf
(4.5 KiB) Downloaded 740 times
test.png
(95.3 KiB) Downloaded 10045 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 12F615 comparator programming

Post by medelec35 »

Hi oookey,
I have moved topic to a more appropriate section.

You will need to disable watchdog timer.
If you're not using a pullup resistor on MCLR line then you will need to set Master clear enable to internal.
have you read this:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

Martin
Martin

Post Reply