Can't get program to run

For general Flowcode discussion that does not belong in the other sections.
pmgreene01
Posts: 35
http://meble-kuchenne.info.pl
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Can't get program to run

Post by pmgreene01 »

I am trying to make my first project with a PIC18F25K50. It is just a simple LED blink.

I am using a PICKIT4. The programmer sees the chip and says that programming is successful, but then nothing happens.

I attached my program and my log file.

Thanks.
Attachments
LED_Blink_PIC18F25K50.msg.txt
(3.16 KiB) Downloaded 21 times
LED_Blink_PIC18F25K50.fcfx
(9.67 KiB) Downloaded 23 times

WingNut
Posts: 254
Joined: Tue Jul 13, 2021 1:53 pm
Has thanked: 33 times
Been thanked: 23 times

Re: Can't get program to run

Post by WingNut »

What are you using to program the pic. MPLAB?

pmgreene01
Posts: 35
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Re: Can't get program to run

Post by pmgreene01 »

I got it set up in MPLAB X and the MCC and can program the device with the PICKIT4. I can flash an LED and some other simple stuff.

I then wanted to program it in Flowcode, so I moved over to Flowcode and set up the paths to my MPLAB compiler and the PICKIT4. As I said, it recognizes the chip and says everything is successful, but the LED does not blink.

If I load a functioning program from MPLAB X and then try to program it in Flowcode, it does erase the program, but nothing happens. When I go back to MPLAB, everything works. So I must be missing something.

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: Can't get program to run

Post by medelec35 »

Hello.
the usual reason for hardware not working as expected is incorrect project options settings.
for example, you have got watchdog timer and single supply set to enabled.

With the Watchdog enabled, without reset watchdog commands then your hardware will be watchdog timing out, so it will not work as expected.

If using pickit 4 then single supply should be set to disabled, and not enabled as you have got it set to.

This post is old now, bit there might be some things that still apply
Martin

pmgreene01
Posts: 35
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Re: Can't get program to run

Post by pmgreene01 »

I am still stuck. I have gone through all of the configuration settings and something is still wrong with the clock. My LED blink time is 50x what it should be.

I was able to configure the clock at 48mHz in MPLAB and verified that by defining an interrupt and checking it with a scope. I attached a text file with the configuration settings from MPLAB. I have compared these to the Flowcode settings, but I can't figure out why I can't get it to work correctly.

I also attached my project file again.

If there is a working example program for this chip, then I could also use that as a starting point.
Attachments
MPLAB_48mHz_PIC18F25K50_config.txt
(4.38 KiB) Downloaded 24 times
LED_Blink_PIC18F25K50.fcfx
(14.58 KiB) Downloaded 23 times

kersing
Valued Contributor
Posts: 157
Joined: Wed Dec 02, 2020 7:28 pm
Has thanked: 64 times
Been thanked: 58 times

Re: Can't get program to run

Post by kersing »

You need to keep in mind Flowcode does not set your clock settings for you. The clock speed you provide is only used to calculate delays etc. To set the clock speed you need to add a C code block to your flowchart. Did you do so?

pmgreene01
Posts: 35
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Re: Can't get program to run

Post by pmgreene01 »

Thanks for responding. This is is my first PIC project, so I don't really know how to do that. I copied all of the #pragma statements from the autogenerated MPLAB code into a C-Block and disabled "Write Config on Download" and it is still slow. Using a scope and toggling outputs, it looks like I am off by exactly 48. So it is like the internal clock is running at 1mHz when I wanted it to run at the full 48mHz.

I also saw the statement #define _XTAL_FREQ 48000000 which looked clock related, so I threw that in after all the #pragma stuff and that doesn't seem to make a difference. I am learning on a PIC 18F25K50 because it is one of the free targets. If anyone knows of any example programs that could get me started, that might be helpful.

Code: Select all

// Enter C code below this comment

// Configuration bits: selected in the GUI

// CONFIG1L
#pragma config PLLSEL = PLL3X      // PLL Selection->3x clock multiplier
#pragma config CFGPLLEN = ON       // PLL Enable Configuration bit->PLL Enabled
#pragma config CPUDIV = NOCLKDIV   // CPU System Clock Postscaler->CPU uses system clock (no divide)
#pragma config LS48MHZ = SYS48X8   // Low Speed USB mode with 48 MHz system clock->System clock at 48 MHz, USB clock divider is set to 8

// CONFIG1H
#pragma config FOSC = INTOSCIO     // Oscillator Selection->Internal oscillator
#pragma config PCLKEN = ON         // Primary Oscillator Shutdown->Primary oscillator enabled
#pragma config FCMEN = OFF         // Fail-Safe Clock Monitor->Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF          // Internal/External Oscillator Switchover->Oscillator Switchover mode disabled

// CONFIG2L
#pragma config nPWRTEN = OFF       // Power-up Timer Enable->Power up timer disabled
#pragma config BOREN = SBORDIS     // Brown-out Reset Enable->BOR enabled in hardware (SBOREN is ignored)
#pragma config BORV = 190          // Brown-out Reset Voltage->BOR set to 1.9V nominal
#pragma config nLPBOR = OFF        // Low-Power Brown-out Reset->Low-Power Brown-out Reset disabled

// CONFIG2H
#pragma config WDTEN = OFF         // Watchdog Timer Enable bits->WDT disabled in hardware (SWDTEN ignored)
#pragma config WDTPS = 32768       // Watchdog Timer Postscaler->1:32768

// CONFIG3H
#pragma config CCP2MX = RC1        // CCP2 MUX bit->CCP2 input/output is multiplexed with RC1
#pragma config PBADEN = ON         // PORTB A/D Enable bit->PORTB<5:0> pins are configured as analog input channels on Reset
#pragma config T3CMX = RC0         // Timer3 Clock Input MUX bit->T3CKI function is on RC0
#pragma config SDOMX = RB3         // SDO Output MUX bit->SDO function is on RB3
#pragma config MCLRE = ON          // Master Clear Reset Pin Enable->MCLR pin enabled; RE3 input disabled

// CONFIG4L
#pragma config STVREN = ON         // Stack Full/Underflow Reset->Stack full/underflow will cause Reset
#pragma config LVP = OFF           // Single-Supply ICSP Enable bit->Single-Supply ICSP disabled
#pragma config ICPRT = OFF         // Dedicated In-Circuit Debug/Programming Port Enable->ICPORT disabled
#pragma config XINST = OFF         // Extended Instruction Set Enable bit->Instruction set extension and Indexed Addressing mode disabled
#pragma config DEBUG = OFF         // Background Debugger Enable bit->Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins

// CONFIG5L
#pragma config CP0 = OFF           // Block 0 Code Protect->Block 0 is not code-protected
#pragma config CP1 = OFF           // Block 1 Code Protect->Block 1 is not code-protected
#pragma config CP2 = OFF           // Block 2 Code Protect->Block 2 is not code-protected
#pragma config CP3 = OFF           // Block 3 Code Protect->Block 3 is not code-protected

// CONFIG5H
#pragma config CPB = OFF          // Boot Block Code Protect->Boot block is not code-protected
#pragma config CPD = OFF          // Data EEPROM Code Protect->Data EEPROM is not code-protected

// CONFIG6L
#pragma config WRT0 = OFF         // Block 0 Write Protect->Block 0 (0800-1FFFh) is not write-protected
#pragma config WRT1 = OFF         // Block 1 Write Protect->Block 1 (2000-3FFFh) is not write-protected
#pragma config WRT2 = OFF         // Block 2 Write Protect->Block 2 (04000-5FFFh) is not write-protected
#pragma config WRT3 = OFF         // Block 3 Write Protect->Block 3 (06000-7FFFh) is not write-protected

// CONFIG6H
#pragma config WRTC = OFF         // Configuration Registers Write Protect->Configuration registers (300000-3000FFh) are not write-protected
#pragma config WRTB = OFF         // Boot Block Write Protect->Boot block (0000-7FFh) is not write-protected
#pragma config WRTD = OFF         // Data EEPROM Write Protect->Data EEPROM is not write-protected

// CONFIG7L
#pragma config EBTR0 = OFF        // Block 0 Table Read Protect->Block 0 is not protected from table reads executed in other blocks
#pragma config EBTR1 = OFF        // Block 1 Table Read Protect->Block 1 is not protected from table reads executed in other blocks
#pragma config EBTR2 = OFF        // Block 2 Table Read Protect->Block 2 is not protected from table reads executed in other blocks
#pragma config EBTR3 = OFF        // Block 3 Table Read Protect->Block 3 is not protected from table reads executed in other blocks

// CONFIG7H
#pragma config EBTRB = OFF        // Boot Block Table Read Protect->Boot block is not protected from table reads executed in other blocks


#define _XTAL_FREQ 48000000

pmgreene01
Posts: 35
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Re: Can't get program to run

Post by pmgreene01 »

As a follow on, I changed the Flowcode clock setting to 1mHz in "Project Options" and then created some interrupts. The interrupt intervals match up with the calculated intervals in Flowcode, so I think that this confirms the internal clock is running at 1mHz and not 48Mhz. The odd thing is that the blink interval of the LED is still off by a factor of 5.

pmgreene01
Posts: 35
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Re: Can't get program to run

Post by pmgreene01 »

I figured it out. I found the OSCCON register. Now it all works correctly. Thanks for pointing me in the right direction.

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: Can't get program to run

Post by medelec35 »

Hello.
To set the internal osc to 48MHz
Select Component Libraries ribbon and click on the magnifying glass on the far left.
Enter intosc and you will see the Internal Oscillator component within the search results ,drag it to your 2D panel.
To make 48 MHz, we need to run the internal osc at 16MHz then use the PLL within the configuration settings to x 3

Within the properties of the Internal Oscillator component, select Oscillator speed of 16000000.
Copy the Code that is produced i.e.

Code: Select all

OSCCON = 0x70;
as you will need to add a Code clock at the very start of your flowchart with the correct OSCCON value.

Finally, within project options make sure that Clock speed (MHz) [defines delay -related timings] is set to 48.
Within configure Set top PLL Multiplier selection bit to Output frequency is 3x the input frequency

The next PLL Multiplier selection bit down to Oscillator multiplied by 3 or 4, Depending on the PLLSEL bit
If all the above steps are carried out then the internal osc should run at 48MHz.

Edit, after sending a reply I got a warning 'At least one new post has been made to this topic. You may wish to review your post in light of this.'
So, I will still post as others might learn from this.

I'm glad you now are all sorted.
Martin

Post Reply