I am a newcommer to Flowcode and use of the Pic chip.
I would welcome help with the following problem I have spent hours trying to resolve.
I have written a program that reads a light sensor and activates outputs depending on
level and times. The simulation now runs as required after mods to program. The problem is
once it is programmed into a 16f818 the program still runs as required but delays of 1 second
take over a minute!.
The chip configuration is set for internal Oscillator at 4mhz. I use a Willem PCB45 programmer
with 0.98 software. Config setting is x3f70 for Osccon register.
Further playing today shows I can set the clock speed in Flow code down to 100000 and the program
runs faster but nowhere as fast as it should be, config settings seem ok for internal Osc. any ideas?
Thanks
Slow running 16f818
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Slow running 16f818
The config word is appropriate, but you need to set the value of the OSCCON register at the beginning of your code. Do this by inserting a C code icon with the following in it:
The internal oscillator block for this chip defaults to 31.25 kHz (see the datasheet for the device).
Also note that the "clock speed" setting within Flowcode is used by Flowcode to calculate the delay times, and does not set the oscillator frequency in any way (there are a number of posts on this forum about this).
Code: Select all
osccon = 0x60; //set internal osc to 4MHz
Also note that the "clock speed" setting within Flowcode is used by Flowcode to calculate the delay times, and does not set the oscillator frequency in any way (there are a number of posts on this forum about this).
Re: Slow running 16f818
Thanks for your answer, am I missing something here?
I have added the 'C' code as suggested but still the chip runs very slow
even with this simple outputs on/off program. Any ideas?
This code is for 16f819 that I am trying in case problem was with chip.
//Defines for microcontroller
#define P16F819
#define MX_EE
#define MX_EE_TYPE2
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_B
#define MX_SPI_SDI 1
#define MX_SPI_SDO 2
#define MX_SPI_SCK 4
#define MX_I2C
#define MX_I2C_B
#define MX_I2C_SDA 1
#define MX_I2C_SCL 4
#define MX_PWM
#define MX_PWM_PORT portb
#define MX_PWM_TRIS trisb
#define MX_PWM_CNT 1
#define MX_PWM_1 3
//Functions
#include <system.h>
#pragma CLOCK_FREQ 4000000
//Configuration data
#pragma DATA 0x2007, 0x3f70
//internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V3\FCD\internals.c"
//Macro function declarations
//Variable declarations
//Supplementary defines
//Macro implementations
//Supplementary implementations
void main()
{
//Initialisation
adcon1 = 0x07;
//Interrupt initialisation code
option_reg = 0xC0;
//C Code
//C Code:
/*Enter C code below these comments
osccon = 0x70; //set internal osc to 4MHz
*/
//Output
//Output: 0 -> PORT B
trisb = 0x00;
portb = 0;
//Loop
//Loop: While 1
while( 1 )
{
//Output
//Output: 0 -> PORT B
trisb = 0x00;
portb = 0;
//Delay
//Delay: 1 s
delay_s(1);
//Output
//Output: 1 -> PORT B
trisb = 0x00;
portb = 1;
//Delay
//Delay: 1 s
delay_s(1);
//Output
//Output: 2 -> PORT B
trisb = 0x00;
portb = 2;
//Delay
//Delay: 1 s
delay_s(1);
//Output
//Output: 0 -> PORT B
trisb = 0x00;
portb = 0;
//Delay
//Delay: 1 s
delay_s(1);
}
mainendloop: goto mainendloop;
}
I have added the 'C' code as suggested but still the chip runs very slow
even with this simple outputs on/off program. Any ideas?
This code is for 16f819 that I am trying in case problem was with chip.
//Defines for microcontroller
#define P16F819
#define MX_EE
#define MX_EE_TYPE2
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_B
#define MX_SPI_SDI 1
#define MX_SPI_SDO 2
#define MX_SPI_SCK 4
#define MX_I2C
#define MX_I2C_B
#define MX_I2C_SDA 1
#define MX_I2C_SCL 4
#define MX_PWM
#define MX_PWM_PORT portb
#define MX_PWM_TRIS trisb
#define MX_PWM_CNT 1
#define MX_PWM_1 3
//Functions
#include <system.h>
#pragma CLOCK_FREQ 4000000
//Configuration data
#pragma DATA 0x2007, 0x3f70
//internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V3\FCD\internals.c"
//Macro function declarations
//Variable declarations
//Supplementary defines
//Macro implementations
//Supplementary implementations
void main()
{
//Initialisation
adcon1 = 0x07;
//Interrupt initialisation code
option_reg = 0xC0;
//C Code
//C Code:
/*Enter C code below these comments
osccon = 0x70; //set internal osc to 4MHz
*/
//Output
//Output: 0 -> PORT B
trisb = 0x00;
portb = 0;
//Loop
//Loop: While 1
while( 1 )
{
//Output
//Output: 0 -> PORT B
trisb = 0x00;
portb = 0;
//Delay
//Delay: 1 s
delay_s(1);
//Output
//Output: 1 -> PORT B
trisb = 0x00;
portb = 1;
//Delay
//Delay: 1 s
delay_s(1);
//Output
//Output: 2 -> PORT B
trisb = 0x00;
portb = 2;
//Delay
//Delay: 1 s
delay_s(1);
//Output
//Output: 0 -> PORT B
trisb = 0x00;
portb = 0;
//Delay
//Delay: 1 s
delay_s(1);
}
mainendloop: goto mainendloop;
}
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Slow running 16f818
Your C code is within the comment block:
You need to clear the whole box and just put:
Code: Select all
/*Enter C code below these comments
osccon = 0x70; //set internal osc to 4MHz
*/
Code: Select all
osccon = 0x70; //set internal osc to 4MHz
Re: Slow running 16f818
Thanks , problem solved.
Just one more thing if thats o.k
What page of the data sheet can I find the information for Osccon Register settings?
Just one more thing if thats o.k
What page of the data sheet can I find the information for Osccon Register settings?
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Slow running 16f818
In my version of the datasheet, it's in chapter 4. The most useful bit is right at the end (i.e. the actual register bit definitions), but there should be a section or two within the chapter with more detail.
Re: Slow running 16f818
Sorry to be a pest but in my copy of the data sheet osccon register x70 (01110000) shows speed set to 8Mhz if
I'm looking at the information correctly, is it 4mhz or 8 mhz?
I'm looking at the information correctly, is it 4mhz or 8 mhz?