One second LED flasher

From Flowcode Help
Jump to navigationJump to search

If Flowcode is mis-configured for your hardware then time dependent code such as delays, communication bauds, timers etc. will fail to run as intended. A very simple way of confirming your hardware is configured correctly in Flowcode is with the use of a one second flasher program.

The one second flasher program simply consists of a loop, a couple of delays and a couple of output icons. The idea is to switch an output pin on and off to which a LED and series resistor (200R - 1K) can be attached to confirm if the delays are approximately equal to a second. The likelihood is that the delays will be either bang on one second or will be way out confirming there is a configuration issue.

Here is a example of a one second flasher program.


If the delays on the hardware do not equal one second or the LED does not flash at all then here are some areas to check.

Is the Project Options project clock speed setup correctly for your oscillator source? This value can be selected from the drop down list or typed in directly to allow for any oscillator speed.


Is the Project Options configuration setup correctly for your oscillator source? These settings will vary from device to device so it is often necessary to refer to the device datasheet for details on specifics.


Generally speaking the Watchdog timer, Low Voltage Programming and Extended CPU settings should all be set to disabled unless you specifically need the functionality they provide.

PIC Specific

External Oscillator 8-Bit PIC

For an 8-bit PIC device a crystal oscillator below 4MHz is the XT option, 4MHz or above is the HS option.

External Oscillator 16-Bit PIC

For an 16-bit PIC device a crystal oscillator below 10MHz is the XT option, 10MHz or above is the HS option. High speed devices may require a PLL to be configured via the configuration settings or enabled using a C code icon at the start of your program.

Example PLL C code for a dsPIC33EP device running at 140MHz (70MIPs) from an 8MHz oscillator.

//Setup configuration for 70MIPs using 8MHz Crystal

PLLFBD = 68; //M=70

CLKDIVbits.PLLPOST = 0; // N1=2

CLKDIVbits.PLLPRE = 0; // N2=2

OSCTUN = 0; //Tune FRC oscillator, if FRC is used

RCONbits.SWDTEN = 0; // Clock switching to incorporate PLL

__builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011)

__builtin_write_OSCCONL(0x01); // Start clock switching

while(OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur

while(OSCCONbits.LOCK != 1); // Wait for PLL to stabilise and lock

//USB H/W initialization for 70 MIPs

ACLKCON3 = 0x24C1;

ACLKDIV3 = 0x7;


while(ACLKCON3bits.APLLCK != 1); // Wait for PLL to lock

Internal Oscillator

Internal clock speeds will vary depending on your device and may need a C code icon at the start of your program to configure them correctly to the frequency you require. The INTOSC Helper component will help you determine the required C code.

AVR Specific

AVR hardware has a divide by 8 configuration setting which can often be enabled by default, e.g. if your 1 second delay is lasting 8 seconds.

Do not disable the SPI clock in the AVR configuration as this will effectively disable the serial programming interface used by the AVRISP mkII and TinyISP etc.

Arduino devices should come pre-programmed with the right configuration settings and bootloader. The serial interface is required to re-program the bootloader if required.