Problems with 16F1939

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

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: Order not received.

Post by medelec35 »

Steve wrote:This shows that your interrupt routines involve a fair amount of processing. Ideally you should keep these interrupt routines as simple as possible.
Sorry I posted he flowchart that gives a warning, and since my hardware works ok, I did not notice any warnings to be honest.
The stack corruption warning is a bit odd, since only one 7seg is lit on each activation of interrupt.
So either the 7seg uses delays, so interrupt will have to be exited to do that, hence corruption would occur.
Or the compiler can’t distinguish from how many 7segs within interrupt to how many are used at one time. Therefore all should be OK?
I thought the The interrupt is has been kept faily short?
interrupt corruption.png
(13.27 KiB) Downloaded 8158 times
Someone who know more than I do will have to answer that one.

Martin
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Order not received.

Post by Spanish_dude »

Hi,

It's because of the "MOD" in your calculation box.

You could change your calculation box to :

Code: Select all

if (Count1 >= 3)
    Count1 = 0;
else
    Count1 = Count1+1;
(This can be done with Flowcode icons.)

Or you could use a C code block and ad this :

Code: Select all

Count1 = Count1 >= 3 ? 0 : Count1 + 1;
http://en.wikipedia.org/wiki/Ternary_operation

Nicolas

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: Order not received.

Post by medelec35 »

Thanks Nicolas
Well spotted!
I did not realise that MOD could cause the issue.
What I should of done is removed each component/calculation from interrupt until corruption message disappears!
I have updated the flowchart without MOD in the interrupt.
Martin
Attachments
LED Voltmeter2.fcf
(13.5 KiB) Downloaded 444 times
Martin

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: Order not received.

Post by Creative25 »

Thanks Martin for the new Program.
Now it does not give any serious error messages when downloading to the chip.

Code: Select all

Caution: argument of 'delay_us' calls must have a value of 1 or more
Caution: Delay inaccurrate: 'delay_us', Delay overhead:0.01ms, Unit delay:0.001ms, Delay resolution:4 units
Warning unreferenced functions removed:
	 FCI_FLOAT_TO_STRING	 in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
	 FCI_NUMBER_TO_HEX	 in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
	 FCI_STRING_TO_INT	 in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
	 FCI_STRING_TO_FLOAT	 in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
	 Wdt_Delay_S	 in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
	 Wdt_Delay_Ms	 in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
	 isinf	 in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
	 FCD_ADC0_ReadAsInt	 in: C:\Users\Admin\AppData\Local\Temp\LED Voltmeter2-1.c
	 FCD_ADC0_ReadAsVoltage	 in: C:\Users\Admin\AppData\Local\Temp\LED Voltmeter2-1.c
	 FCD_ADC0_ReadAsString	 in: C:\Users\Admin\AppData\Local\Temp\LED Voltmeter2-1.c
I have completely rebuilt my board to make sure that there is no fault on it.
For testing the ADC function i have put a potentiometer beetween VDD and VSS and connected the center pin to ADC4 pin number seven.
When I turn the pontentiometer the Numbers are changing however not to the correct voltage but to random numbers, still the same as before. 0.00 0.70 1.20 2.70 and 3.70.

Is there anyone who has successfully used ADC on a 16F1939?

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: Order not received.

Post by medelec35 »

Hi, Creative25
Creative25 wrote:For testing the ADC function i have put a potentiometer beetween VDD and VSS and connected the center pin to ADC4 pin number seven.
When I turn the pontentiometer the Numbers are changing however not to the correct voltage but to random numbers, still the same as before. 0.00 0.70 1.20 2.70 and 3.70.

Is there anyone who has successfully used ADC on a 16F1939?
Just a guess, but I wonder if it’s the same issue as:
http://www.matrixmultimedia.com/mmforum ... =29&t=8746
?
Since symptoms sound very similar indeed.

I know its a differnt chip, but ADC may work in a similar way?

Martin
Martin

User avatar
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: Order not received.

Post by Benj »

Yes I agree with Martin, very likely caused by the same problem.

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: Order not received.

Post by Creative25 »

Excellent!!! :D :D :D
This link provided the solution.
I inserted the custom code, into the ADC settings and now the ADC is working properly.
Does the C file provided on the link also work for the Pic 16F1939?

There is still a small bug, when I look carefully every few seconds the display briefly goes off for a few milliseconds.
You have to look carefully to see it.

What coulcd be the cause of this?
Is the chip resetting itself?

Uli

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: Order not received.

Post by medelec35 »

Great glad that link helped.
Rosenbaum did a good job in spotting that bug.
Creative25 wrote: There is still a small bug, when I look carefully every few seconds the display briefly goes off for a few milliseconds.
You have to look carefully to see it.

What coulcd be the cause of this?
Is the chip resetting itself?

Uli
A way in which you can find out if chip is resetting, is just think of a number e.g 0, then at the beginning of your code, just before the main loop starts, set say the centre 7seg to 0 for 2 seconds for example. then every time the centre digit shows a 0 for two seconds, you know the chip is resetting, Since this will only occur on chip reset.

I suspect it could be resetting because I have no end of problems with 16F1824 and 16F1827 kept on resetting, and I keep giving up on them.
Believe it or not they kept resetting after reading from analogue channels. Not every time, and not with the same channel.
I was using internal osc with mclr and watchdog disabled. I don't know to this day if a bug with Flowcode or the chip its self?
I may get back to seeing if I can find the cause.

Martin
Martin

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: Order not received.

Post by Creative25 »

:D In chip options I disabled MCLR and I also disabled the watchdogtimer.
Since then the display is steady.
So I guess the problem is solved.
Thanks to all who helped to make a success of my first program.
Uli

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: Order not received.

Post by medelec35 »

Nice one. glad your hardware is working :)

As for watchdog. That is used to reset your hardware if program hangs.
It works by having several commands to reset watchdog register placed within your code. If a clear command is not reached within say 18ms, then hardware is automatically reset!
This can be done automatically with Flowcode V4 by going into view project options, then selecting Auto clear watchdog.
To make sure watchdog is always cleared you can also add a C code box with MX_CLEAR_WATCHDOG; in several places.
This is not required of course is watchdog is set to disabled.
That is your job to decide.
As a default watchdog is enabled. If left enabled and you don't add MX_CLEAR_WATCHDOG; or enable Auto clear watchdog, then your hardware WILL keep resetting!

With MCLR there are some chips (12F675 & 16F883 for example) that don't like to be programmed that easily if using internal osc and MCLR is set to disabled.
See http://www.matrixmultimedia.com/mmforum ... 37&p=20028 for solution.

It is genuinely recommended to enable MCLR, and use a pull=up resistor, unless you need the extra i/p when MCLR is set for i/p on some devices.

Martin
Martin

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: Order not received.

Post by Creative25 »

Thanks now i put on auto clear and now it works with the watchdog timer on.
I changed the program to read as intern, and put a formula to double the int. So the maximum reading could be 20.46 volts.
For measuring up to 20 Volts I put a voltage divider and Adjusted the potentiometer so the reading is perfect. It can read with an accuracy of 0.02 Volts.
And that is good enough for me.

I noticed one slight problem if the volage is between two values is starts jumping up and down very fast. If I change the 100us delay to a longer than that, is does not show the right results. How could I change the program that it updates the Voltage at a slower rate, say I would like it to update about every 500ms.
Also I would like to add anoter ADC to read temperature can I put it in the same loop or do I have to add a separate loop for this purpose?
Also if I want to add any delay to the main Program it gives me a serious error message.
Regards:
Uli
Attachments
LED Voltmeter2.1.fcf
(10 KiB) Downloaded 399 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: Order not received.

Post by medelec35 »

Creative25 wrote:How could I change the program that it updates the Voltage at a slower rate, say I would like it to update about every 500ms.
Also I would like to add anoter ADC to read temperature can I put it in the same loop or do I have to add a separate loop for this purpose?
Also if I want to add any delay to the main Program it gives me a serious error message.
Regards:
Uli
Best thing to do is remove delay from the timer 0 interrupt, since there is a delay in-between the interrupt being triggered any way. Delay between triggering is approx 1/488 ~ 2ms
then you can add a delay in main to slow the ADC read down.
You can also place the temperature read routine in main or add a call Read_Temperature component then you can add a routine for reading temperature within Read_Temperature Macro.
That's up to you as Flowcode is very flexible like that.

Hope this makes sense.

Martin
Martin

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: Order not received.

Post by Creative25 »

Thanks.
It is now coming right with the delays etc.
Now I added a Ntc temperature sensor.
I make it to display the temperature reading by default. And at the pusching of a button it should display the voltage of the Battery.
However it seems the 16f1939 chip does not read the Input.
When I press the button I can measure the Input is getting power on pin 30 but nothing happens.
I also configured it that it should put pin 21 High but there also is no power, so I suspect the chip is not reading the input.
Or there is something seriously wrong with my program.
Regards:
Uli
Attachments
LED Voltmeter2.4.fcf
(16 KiB) Downloaded 355 times

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: Problems with 16F1939

Post by Creative25 »

:D
I changed the wiring and connected the pusbutten on port E 1, pin number 9.
Since then it is working fine. I do not know why it does not want to read on D7, pin number 30.
Uli

User avatar
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: Problems with 16F1939

Post by Benj »

Hello Uli,

It could be the PortD pin is still configured as a analogue input pin rather then a digital input pin.

You could try adding the line of C code to the start of your program and this should then allow you to use the PortD pin as an input.

anseld = 0x00;

Let me know how you get on if you decide to give it a go and if this works then I will update the FCD file to match.

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: Problems with 16F1939

Post by Creative25 »

Hi Benj
Thanks for the advice.
I entered the C code in the Beginning of the program.
Now the pushbutton also works on pin Nr 30
I hope now all the problems with the Pic 1939 are sorted out.

I have a real beginners question.
I brought daylight the Led seem to be quite dim. If I run the refresch macro wit a 2 second delay i get the following measurements.
Supply voltage 4.96 volt.
Voltage on the emitter of the BC337 Transistor is only 3.7 volts is that normal? Between the IC and the transistors base i put a 1k resistor.
Voltage on the Base pin is 4.94 volts.
Voltage across the display digits when on is 2 volts.
On that slow speed the Led segments are quite bright but at higher speed it is quite dim, which I guess is normal because the Led's are on only 25% of the time.
Is there a way I can get it to be brighter? Or does that sorted when you put a dark glass in front of it?

Uli

Post Reply