Page 1 of 1

Problem with comparator lab (Flowcode4)

Posted: Fri Aug 21, 2009 5:06 pm
by alexander70
Hello! I have a problem with the implementation of Lab 1: Simple Compare (66 page of the document http://ww1.microchip.com/downloads/en/D ... 41381A.pdf ). I do laboratory work using PICKIT2 with PIC16F887 on board, if necessary, modify the program, as well as laboratory work completed for the device PIC16F690. In this laboratory work, I made the changes accordingly: 19 pin PIC16F690 changed in 22 PIN PIC16F887,
18 pin PIC16F690 changed on 19 PIN PIC16F887, 17 pin PIC16F690 changed on 23 PIN PIC16F887. Diode LED1 on the scheme in FIGURE 3-1, I changed the polarity to the anode was connected to Vss (otherwise it would not light up). I have done as it is written in this book, but the comparator in PICKIT2 not work. I put this project Flowcode 4. Where is mistake?

Respectfully, Alexander

Re: Problem with comparator lab (Flowcode4)

Posted: Fri Aug 21, 2009 9:38 pm
by Benj
Hello

Firstly are you using an 16F877 or a 16F877A?

I think the problem lies in the chip configuration settings. :

A) If you are using a 16F877

Click on Chip and Configure and then click the switch to expert mode button set the oscillator setting to XT for a crystal speed of 4MHz or under and HS for a crystal speed above 4MHz. Make sure things like code protect and flash protect etc are set to off.

B) If you are using a 16F877A

Change the target via the View -> Project options menu and then Click on Chip and Configure and select the XTAL setting.


Then recompile and program. That should allow your program to work correctly.

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 3:10 am
by alexander70
Hi! As I wrote earlier, I use the PICkit β„Ά 2 Debug Express ( http://www.microchip.com/stellent/idcpl ... e=en023805 ), which contains chip PIC16F887 on board. Previous 5 labs I carried out without problems,
programs run on the 44 pin Demo board too, not only in my computer. And in this lab (as in the previous labs, the files that I put here) PIC16F887 is configured for internal RC no clock 4 MHz.

Respectfully, Alexander

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 5:04 am
by medelec35
Made a couple of modifications to your Flowcode- Added osccon = 0x60; c box to set internal osc at 4MHz
Changed config so MCLR is set for internal.
Not got the board to test it on, so not sure if did the trick.
Can you please let me know if sorted your problem out.
Thanks.

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 5:25 am
by alexander70
Π΅ code should be added only in order internal oscillator frequency of 8 Mhz. For the 4 Mhz can be customized in Flowcode without inserting C code. As I wrote earlier, the previous 5 labs are functioning properly at the Demo board.

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 11:00 am
by medelec35
I may be wrong here, but I believe flowcode will use the oscillator clock speed settings for delay calculations only. I don't think it will configure your hardware to run internal osc at set clock speed. For that has to be set either by software hence osccon command or in other microcontrollers by programmer or flowcode config settings. Perhaps that point can be verified? so I believe your internal osc is running at wrong speed.16F887 is the former. i.e. int osc is set by software. obviously its up to you if you try with code I posted. What have you got to loose? It will either work and I'm right, or it wont then I'm wrong. does not make any odds to me, but it is nice knowing either way. If your previous demos do not require a delay, and just turn LED's on and off by activating a switch, then it all would appear to work fine. It when you put delay in it will go wrong. Try putting a 500ms delay into one of your working demos, or just create a simple 1Hz flashing LED.

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 11:10 am
by Benj
Hello Alexander

I think I have discovered the reason the example is not working on the 16F877. The 16F877 does not have the comparitor hardware peripheral that the 16F690 has. So its never going to work with this chip. :cry: In fact im surprised the code compiled at all. I guess the PWM peripheral shares registers with the comparitor peripheral.

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 12:00 pm
by medelec35
Ah. That will teach me to just download labs and see if I can get lab 5 working and post it corrected back no wounder it was not tried. I totally miss the point. Sorry about that. it's very hot where I am :mrgreen:

Was I right about flowcode clock settings though, you never know if some one asks a question about that :lol:

So the 2 comparator's on 16F887 are different to 16F690?

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 12:18 pm
by alexander70
Benj wrote:Hello Alexander

I think I have discovered the reason the example is not working on the 16F877. The 16F877 does not have the comparitor hardware peripheral that the 16F690 has. So its never going to work with this chip. :cry: In fact im surprised the code compiled at all. I guess the PWM peripheral shares registers with the comparitor peripheral.

PIC16F887 has 2 analog comparators http://ww1.microchip.com/downloads/en/D ... 41291F.pdf

How to make them work in the Flow code 4?

Re: Problem with comparator lab (Flowcode4)

Posted: Sat Aug 22, 2009 2:12 pm
by Benj
Hello

Hm the datasheet I was looking at didnt have the comparitor module for the 16F887. Ill have another look and get back to you.

Re: Problem with comparator lab (Flowcode4)

Posted: Thu Sep 03, 2009 8:35 am
by Benj
Hello

Did you have any joy with this. I have had another look through the datasheet and this problem may have something to do with the analogue reference pins. You seem to need to configure them correctly to allow the voltage comparison to work correctly.

Re: Problem with comparator lab (Flowcode4)

Posted: Thu Sep 03, 2009 10:30 am
by alexander70
Hi! I've been thinking about it. I noticed that the output of the first comparator PIC16F690 corresponds to the port A2 (RA2/T0CKI/INT/C1OUT). And PIC16F887 - Port A4 (RA4/T0CKI/C1OUT). May be this error? Port A must be initialized differently?


Port A must be initialized in this way?

original:
trisa = 0b11111011; //configures PORTA pin direction
cm1con0 = 0b10100000; //configures comparator 1

must be at using PIC16F887
trisa = 0b11101111; //configures PORTA pin direction
cm1con0 = 0b10100000; //configures comparator 1

Now I can not verify this because I am now out of work (in the summer vacation).
After 2 weeks I checked it out.

Re: Problem with comparator lab (Flowcode4)

Posted: Thu Sep 24, 2009 1:15 pm
by alexander70
I just want to clarify, the diagram below there are no errors? LED correctly enabled?

Re: Problem with comparator lab (Flowcode4)

Posted: Wed Sep 30, 2009 7:40 am
by alexander70
Everything works, I made a mistake with pins:)