Problem with comparator lab (Flowcode4)
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Problem with comparator lab (Flowcode4)
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
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
- Attachments
-
- comp1.fcf
- Flowcode 4 project
- (5 KiB) Downloaded 474 times
Respectfully, Alexander
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with comparator lab (Flowcode4)
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Problem with comparator lab (Flowcode4)
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
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
- Attachments
-
- labs-flowecode4.zip
- 5 labs
- (191.14 KiB) Downloaded 450 times
Respectfully, Alexander
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Problem with comparator lab (Flowcode4)
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.
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.
- Attachments
-
- 5.fcf
- (14 KiB) Downloaded 405 times
Martin
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Problem with comparator lab (Flowcode4)
Π΅ 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.
Respectfully, Alexander
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Problem with comparator lab (Flowcode4)
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.
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with comparator lab (Flowcode4)
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.
In fact im surprised the code compiled at all. I guess the PWM peripheral shares registers with the comparitor peripheral.
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.

Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Problem with comparator lab (Flowcode4)
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
Was I right about flowcode clock settings though, you never know if some one asks a question about that
So the 2 comparator's on 16F887 are different to 16F690?

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

So the 2 comparator's on 16F887 are different to 16F690?
Martin
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Problem with comparator lab (Flowcode4)
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.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?
Respectfully, Alexander
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with comparator lab (Flowcode4)
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.
Hm the datasheet I was looking at didnt have the comparitor module for the 16F887. Ill have another look and get back to you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with comparator lab (Flowcode4)
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Problem with comparator lab (Flowcode4)
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.
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.
Respectfully, Alexander
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Problem with comparator lab (Flowcode4)
I just want to clarify, the diagram below there are no errors? LED correctly enabled?
- Attachments
-
- 2.jpg (81.02 KiB) Viewed 12740 times
Respectfully, Alexander
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Problem with comparator lab (Flowcode4)
Everything works, I made a mistake with pins:)
Respectfully, Alexander