12F615 comparator programming

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

Moderators: Benj, Mods

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

12F615 comparator programming

Postby oookey » Wed May 15, 2013 9:41 am

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/DeviceDoc/41302D.pdf
Thanks :)
oookey
Attachments
Compare and PWM.png
Compare and PWM.png (45.18 KiB) Viewed 9035 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

Postby Kenrix2 » Sat May 18, 2013 4:51 am

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.
These users thanked the author Kenrix2 for the post (total 2):
oookey (Sat May 18, 2013 5:18 am) • medelec35 (Sat May 18, 2013 8:41 am)
Rating: 10.53%
 

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

Re: 12F615 comparator programming

Postby oookey » Sat May 18, 2013 5:51 am

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

Postby Kenrix2 » Sat May 18, 2013 6:23 am

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

Postby oookey » Tue May 21, 2013 4:37 am

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 481 times
test.png
test.png (95.3 KiB) Viewed 8959 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: 12F615 comparator programming

Postby medelec35 » Tue May 21, 2013 7:32 am

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:
viewtopic.php?f=26&t=6936

Martin
These users thanked the author medelec35 for the post:
oookey (Tue May 21, 2013 9:03 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.