Is your Project Not working? Help and General Advice
Posted: Mon Dec 14, 2009 4:28 pm
Here are some basic solutions.
First make a very simple 1Hz flasher, using an LED and something like 270R resistor in series.
E.g:
If LED not flashing at correct rate (or at all) then check:
A) All voltages are correct. VDD or VCC = +5V. VSS or VEE=0V. Measure output connected to LED with meter. You could have LED connected wrong way around.
B) Pin Functions. Pin may not be a bi-directional port capable of sourcing and sinking current. E.g. Could be an I/P only or open source. The latter means it can only sink current, so you will need to connect anode of LED via a resistor to +5V. Cathode of LED to pin (not to 0V) then LED is off when pin O/P is high and LED is on when pin O/P is low.
C) Configuration settings:
1) Clock frequency.
For V3 Go to 'Chip', 'Clock Speed'
For V4 Go to 'View', 'Project Options', 'Clock Speed'
Make sure 'Clock Speed' matches the oscillator running speed of your microcontroller. If correct speed is not one of the drop-down options, then manually type correct speed in Hz. These setting only controls the timing loops for delays and any time dependent routines it does not set the speed of your hardware. The speed of hardware is determined by crystal or resonator frequencies, Value of R C network or internal oscillator value.
Using the internal oscillator:
A lot of microcontrollers must have C box at the beginning of Main with something like
osccon = 0x60; (This makes the microcontroller I'm using run with internal oscillator at 4MHz).
Or osccon = 0x70; (This makes the microcontroller I'm using run with internal oscillator at 8MHz).
Consult the microcontroller datasheet for more details. Don't forget the semicolon at the end of C statement
Even if you have not got a Matrix EB006 or other Matrix programmer it is a good idea to have PPP installed and with both Flowcodes V3 and V4 select 'Chip', 'Compiler options' then have 'Use external program to set configuration options' selected. Then click OK. This will ensure the correct configuration is sent to chip via compiled hex file.
Now select 'Chip', 'Configure' then click 'Switch To Expert Config Screen'. If you have not got matrix programmer or pickit, then just select 'Chip' then 'Compile to Hex'. This will create a file with the project name and hex extension, which can be loaded into your programmer for programming micocotroller chip.
2) Oscillator Selection. If using internal oscillator then it is best set on INTRC as Port I/O
If using external crystal 4 MHz or over then select HS
If External Crystal is under 4 MHz then select XT
3) Watchdog Timer. I would advise this to be Off.
If left on and 'Auto clear watchdog' (V4 and above only) is not selected or clear_wdt(); (all Flowcode versions) is not used then microcontroller will keep resetting itself before it has had a chance to run its code. So LED will not flash.
4) MCLR or Master Clear Enable. Depending with target device you have got. If enabled then microcontroller will only work when pin associated with MCLR is at +5V. When MCLR pin is at less than +5V i.e. not connected then microcontroller is at permanent reset state so will not run.
Unless you want to have a reset switch connected to MCLR (using a pull-up resistor and use a normally open switch to short pin to 0V to reset) then have MCLR set to internal.
5) Background debug (if applicable to your target device). Leave this Disabled. If left Enabled this will use pins RB6 and RB7 and you will get some puzzling results if any I/P or O/P device are connected to these pins.
6) Low Voltage programming (LVP). It is recommended to have LVP disabled. If left enabled, then a pin (usually B5) will not be available for any i/p or o/p use.
So if you are using B5 and you are not getting the desired o/p, or i/p is not working, then check LVP settings.
C) General use of Flowcode.
If using port masking, only Bits ticked can be controlled (or masked to work). All bits unticked will not have its state changed.
If you have 'Entire port' selected and output set to 1, then bit one will only be high if 'Used Masking' is not selected, or if 'Used Masking' is selected and Bit 0 is ticked. All other Bits will be low.
Important Note:
You may find that using inputs that the results are not as expected/
If masking or single bits are not used, then any i/p that does not have a load connected to either +V or 0V will be floating.
If any pins are floating then you must disable them by selecting Use masking.
Make sure any floating pins are un-ticked and only have pins ticked that will be used.
This can caused by an unconnected pin, or a calculation that is wrong e.g Number = 23. 45 instead of Number = 23.45 (note the space where there should not be one!). Or could be C code box with semicolon missing at the end.
Note: If you leave a semicolon off the end of statement in supplementary code box then you will get a 'general error' and not missing semicolon error!
Another Common cause is if you have loaded a flowcode example, then changed the target device, so new device has not got the same ports as the original target device. When that happens, pins become unconnected.
E.g With a keypad.
Right click on the keypad that is on the panel, then select 'connections'
Make sure all connections are valid, and not showing unconnected!
To check for errors E.g when compling you getIf you download Notepad++ or notepad2 (or any other notepad replacement that shows line numbering).
Then in 'Chip, 'Compiler Options' Where is says file viewer, just browse to the new notepad replacement. You only need to do this once.
Now compile to hex. Note the top line number within brackets e.g: C:\path\file_Name.c(610): error: missing semicolon
You are interested in line 610.
Next Click on 'Chip' , View C....
New notepad replacement will load. Scroll down to line 610.
Look for any mistakes along that line.
If you can't remember the lines showing up with errors, just look when the flowchart is saved for a file with File_Name.msg
You can alternately load File_Name.c file into your editor which displays line numbers.
Timer interrupts macros:
It is important that you do not place any delays or components that will have delays in like LCD displays ,RS232 etc within timer interrupts. Keep interrupt macros as short as possible.
Components like LEDs and calculation icons are OK to use.
If you do use delays which lasts for longer than the timer interrupt takes to trigger, then corruption will occur giving unexpected results.
If you want to update a LCD display after an interrupt has occurred, then set a flag to 1 within interrupt. E.g. update_lcd=1
then for your LCD have a decision branch E.g
If lcd=1 then display macros : lcd=0
E.g if you have only one ADC ReadAsByte.
Then since it is not:
ReadAsInt
ReadAsVoltage
Or
ReadAsString
Then there will be a
Along with some other functions not being used.
Sean has added a very good point:
0/0 is undefined value, which the PIC reads as 255.
Thanks to nmindana for that useful tip.
E.g
Duty = (151/14)*800
Results should be the same with or without brackets
Simulation will show 8628 but the true result would be 8000
Reason for this: Simulation will do (10.785)*800 = 8628
Where as a microcontroller will do (10)*800=800= 8000
A micorocontroller that is not using floating point, will always round down.
e.g. 10.98 will be rounded down to 10
If anyone has any more hints, tips or comments to help people new to Flowcode get their project working then feel free to add to this list.
Thank you.
You can find support page here:
http://www.matrixmultimedia.com/support/
This may give you a solution to your problem.
Regards Martin
First make a very simple 1Hz flasher, using an LED and something like 270R resistor in series.
E.g:
Code: Select all
Loop while 1
A0=1
Delay 500ms
A0=0
Delay 500ms
A) All voltages are correct. VDD or VCC = +5V. VSS or VEE=0V. Measure output connected to LED with meter. You could have LED connected wrong way around.
B) Pin Functions. Pin may not be a bi-directional port capable of sourcing and sinking current. E.g. Could be an I/P only or open source. The latter means it can only sink current, so you will need to connect anode of LED via a resistor to +5V. Cathode of LED to pin (not to 0V) then LED is off when pin O/P is high and LED is on when pin O/P is low.
C) Configuration settings:
1) Clock frequency.
For V3 Go to 'Chip', 'Clock Speed'
For V4 Go to 'View', 'Project Options', 'Clock Speed'
Make sure 'Clock Speed' matches the oscillator running speed of your microcontroller. If correct speed is not one of the drop-down options, then manually type correct speed in Hz. These setting only controls the timing loops for delays and any time dependent routines it does not set the speed of your hardware. The speed of hardware is determined by crystal or resonator frequencies, Value of R C network or internal oscillator value.
Using the internal oscillator:
A lot of microcontrollers must have C box at the beginning of Main with something like
osccon = 0x60; (This makes the microcontroller I'm using run with internal oscillator at 4MHz).
Or osccon = 0x70; (This makes the microcontroller I'm using run with internal oscillator at 8MHz).
Consult the microcontroller datasheet for more details. Don't forget the semicolon at the end of C statement
Even if you have not got a Matrix EB006 or other Matrix programmer it is a good idea to have PPP installed and with both Flowcodes V3 and V4 select 'Chip', 'Compiler options' then have 'Use external program to set configuration options' selected. Then click OK. This will ensure the correct configuration is sent to chip via compiled hex file.
Now select 'Chip', 'Configure' then click 'Switch To Expert Config Screen'. If you have not got matrix programmer or pickit, then just select 'Chip' then 'Compile to Hex'. This will create a file with the project name and hex extension, which can be loaded into your programmer for programming micocotroller chip.
2) Oscillator Selection. If using internal oscillator then it is best set on INTRC as Port I/O
If using external crystal 4 MHz or over then select HS
If External Crystal is under 4 MHz then select XT
3) Watchdog Timer. I would advise this to be Off.
If left on and 'Auto clear watchdog' (V4 and above only) is not selected or clear_wdt(); (all Flowcode versions) is not used then microcontroller will keep resetting itself before it has had a chance to run its code. So LED will not flash.
4) MCLR or Master Clear Enable. Depending with target device you have got. If enabled then microcontroller will only work when pin associated with MCLR is at +5V. When MCLR pin is at less than +5V i.e. not connected then microcontroller is at permanent reset state so will not run.
Unless you want to have a reset switch connected to MCLR (using a pull-up resistor and use a normally open switch to short pin to 0V to reset) then have MCLR set to internal.
5) Background debug (if applicable to your target device). Leave this Disabled. If left Enabled this will use pins RB6 and RB7 and you will get some puzzling results if any I/P or O/P device are connected to these pins.
6) Low Voltage programming (LVP). It is recommended to have LVP disabled. If left enabled, then a pin (usually B5) will not be available for any i/p or o/p use.
So if you are using B5 and you are not getting the desired o/p, or i/p is not working, then check LVP settings.
C) General use of Flowcode.
If using port masking, only Bits ticked can be controlled (or masked to work). All bits unticked will not have its state changed.
If you have 'Entire port' selected and output set to 1, then bit one will only be high if 'Used Masking' is not selected, or if 'Used Masking' is selected and Bit 0 is ticked. All other Bits will be low.
Important Note:
You may find that using inputs that the results are not as expected/
If masking or single bits are not used, then any i/p that does not have a load connected to either +V or 0V will be floating.
If any pins are floating then you must disable them by selecting Use masking.
Make sure any floating pins are un-ticked and only have pins ticked that will be used.
Code: Select all
error: missing semicolon
Note: If you leave a semicolon off the end of statement in supplementary code box then you will get a 'general error' and not missing semicolon error!
Another Common cause is if you have loaded a flowcode example, then changed the target device, so new device has not got the same ports as the original target device. When that happens, pins become unconnected.
E.g With a keypad.
Right click on the keypad that is on the panel, then select 'connections'
Make sure all connections are valid, and not showing unconnected!
To check for errors E.g when compling you get
Code: Select all
failure
Return code = 1
Flowcode was unable to compile the flowchart's C code due to the following errors:'
Then in 'Chip, 'Compiler Options' Where is says file viewer, just browse to the new notepad replacement. You only need to do this once.
Now compile to hex. Note the top line number within brackets e.g: C:\path\file_Name.c(610): error: missing semicolon
You are interested in line 610.
Next Click on 'Chip' , View C....
New notepad replacement will load. Scroll down to line 610.
Look for any mistakes along that line.
If you can't remember the lines showing up with errors, just look when the flowchart is saved for a file with File_Name.msg
You can alternately load File_Name.c file into your editor which displays line numbers.
Timer interrupts macros:
It is important that you do not place any delays or components that will have delays in like LCD displays ,RS232 etc within timer interrupts. Keep interrupt macros as short as possible.
Components like LEDs and calculation icons are OK to use.
If you do use delays which lasts for longer than the timer interrupt takes to trigger, then corruption will occur giving unexpected results.
If you want to update a LCD display after an interrupt has occurred, then set a flag to 1 within interrupt. E.g. update_lcd=1
then for your LCD have a decision branch E.g
If lcd=1 then display macros : lcd=0
Code: Select all
Warning unreferenced functions removed:
So these messages are normal and can be totally ignored.Benj wrote:This means that the functions that you are not calling (referencing) in your program will not be included in the assembled hex file. Basically because your not using them they wont consume memory on the device. This is normal and one of the major advantages of using the C language."Warning unreferenced functions removed:
E.g if you have only one ADC ReadAsByte.
Then since it is not:
ReadAsInt
ReadAsVoltage
Or
ReadAsString
Then there will be a
Code: Select all
Warning unreferenced functions removed:
FCD_ADC1_ReadAsInt in: D:\PWM12F675chip1.c
FCD_ADC1_ReadAsVoltage in: D:\PWM12F675chip1.c
FCD_ADC1_ReadAsString in: D:\PWM12F675chip1.c
Code: Select all
Floating Point Calculations
Sean wrote: There are some differences between the representation of variable and calculations in the PC simulation and the C code downloaded to the microcontroller.
The main calculation illustrates two issues with the way programs handle calculations.
1. A C compiler sometimes needs to be forced to use floating-point calculations to produce intermediate results (it will try to use integer calculations if the input variables are integers). This can be achieved by representing integer constants with one decimal place.
2. Bit shift operators (<< and >>) can not be used as multiplication and division because of the way floating point variables are stored.
The calculation shown below should give the same results as the simulation.
Calculate = (adc1*2048.0) / 1024.0
There is another point to consider when using the default BoostC compiler for the PIC devices.
Floating-point calculations are handled by function calls, so the calculation will need to be re-written into the following form:
Calculate = fmul(int2float(adc1), 2048.0)
Calculate = fdiv(Calculate, 1024.0)
Simulation accepts the normal operators for floating-point calculations (+-*/ etc.) as well as the function calls. The other versions of Flowcode can work with either representation
0/0 is undefined value, which the PIC reads as 255.
Thanks to nmindana for that useful tip.
Code: Select all
Difference between simulation results and real microcontrollers
Duty = (151/14)*800
Results should be the same with or without brackets
Simulation will show 8628 but the true result would be 8000
Reason for this: Simulation will do (10.785)*800 = 8628
Where as a microcontroller will do (10)*800=800= 8000
A micorocontroller that is not using floating point, will always round down.
e.g. 10.98 will be rounded down to 10
If anyone has any more hints, tips or comments to help people new to Flowcode get their project working then feel free to add to this list.
Thank you.
You can find support page here:
http://www.matrixmultimedia.com/support/
This may give you a solution to your problem.
Regards Martin