Using internal configuration registers & particular types of variables

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
planeri
Posts: 11
Joined: Wed Aug 01, 2018 6:20 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Using internal configuration registers & particular types of variables

Post by planeri »

Hi, guys! I'm completely new to Flowcode and I'm evaluating to start working with the program to facilitate the development and updating of firmwares. So far, I've downloaded the Flowcode v8 demo version yesterday and I'm very pleased at the many features I found. I'm familiar with other flowchart based IDEs and C / C++ programming, but I'd like to know how to do some specific things:

- Is there any direct method to change or store the value of a configuration register (other than the ones listed in the "Project Options/Configure" tab) without adding C code? Let's say I need a TMR1 overflow interrupt with a precise lapse of 100 ms and I don't want to call the interrupt macro many times with a counter, in C I usually could initialize the TMR1H and TMR1L registers in each interrupt call with the appropiate values. In flowcode, do I need a custom interrupt for this?

- I noticed I can create an array of any kind of variable (by the way, excellent feature!!), but I'd like to know if I can refer to an array of bools bit by bit or as a byte simultaneously. I saw flowcode has some nice typecasting functions, but I don't know if I could use any of those. It would be something like this in C:

union {
unsigned char byte;
struct{
unsigned sensor1 : 1;
unsigned sensor2 : 1;
unsigned sensor3 : 1;
unsigned sensor4 : 1;
unsigned sensor5 : 1;
unsigned sensor6 : 1;
unsigned sensor7 : 1;
unsigned sensor8 : 1;
}bitv;
}alarms;

alarms.byte = 0; // initialize alarms control byte
alarms.bitv.sensor4 = true; // activate sensor 4 alarm

What would be the best approach to handle this?

I'll probably have more questions in the future, but knowing this things would be a great place to start! :D

Thanks!!

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by QMESAR »

planeri wrote: - Is there any direct method to change or store the value of a configuration register (other than the ones listed in the "Project Options/Configure" tab) without adding C code? Let's say I need a TMR1 overflow interrupt with a precise lapse of 100 ms and I don't want to call the interrupt macro many times with a counter, in C I usually could initialize the TMR1H and TMR1L registers in each interrupt call with the appropiate values. In flowcode, do I need a custom interrupt for this?
Hi welcome to the forum and I am sure you will enjoy Flowcode :D

You are not limited to the base settings FC allows for interrupts or any any thing for that matter,
You can access any register in a micro as in any C language programming by using a C Call Icon on your Flowchart.as you see below you can now add your standard C programming
2.jpg
2.jpg (166.85 KiB) Viewed 7150 times
You can also include your C code in the simulation of your Flowchart by using the C Sim button
3.jpg
3.jpg (17.93 KiB) Viewed 7150 times
You can setup your own custom interrupt and configure your interrupt as you wish here is an example of a Timer interrupt which I configure
to interrupt at my specified time .This methodology also apply for any other interrupt by using a custom interrupt and configure the interrupt to your needs.

1.jpg
1.jpg (57.65 KiB) Viewed 7150 times
I hope this helps as for the use of Structure and Union variables I will leave to Ben and Leigh to answer on this,

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by LeighM »

We don't currently support bit fields, structures or unions directly as Flowcode variables.
Although for some time they have been on the list of things to look at implementing.
In the meantime you can include these, as your C code examples, as QMESAR outlined above.

planeri
Posts: 11
Joined: Wed Aug 01, 2018 6:20 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by planeri »

Thanks for the replies! I've tried to create a custom interrupt for TMR1 but it doesn't seem to work in the simulation. This are the enable and handler codes I used:

Enable Code:

TMR1H = 0xCF; // 100 ms:
TMR1L = 0x2C;
T1CON = 0x35; // T1CKPS 1:8; T1OSCEN disabled; TMR1CS FOSC/4; nT1SYNC do_not_synchronize; TMR1ON enabled; RD16 disabled;
INTCONbits.PEIE = 1; // Enable peripheral interrupts
INTCONbits.GIE = 1; // Enable global interrupts
PIR1bits.TMR1IF = 0; // Clear flag
PIE1bits.TMR1IE = 1; // Enable TMR1 interrupt

Handler:

// Verificar flag de interrupción de TMR1
if (PIR1bits.TMR1IF) {

TMR1H = 0xCF;
TMR1L = 0x2C;
FCM_%n(); // Call Flowcode macro
PIR1bits.TMR1IF= 0; // Clear flag
T1CONbits.TMR1ON =1;
}

I also tried to monitor the initial TMR1L value written adding a flowcode variable named "retval" to the Simulation Debugger and adding the line "FCV_RETVAL = TMR1L;" in the enable code (something similar to the TMR1 Rollover example here: https://www.matrixtsl.com/wiki/index.ph ... -_PICmicro), but the value remains at 0.

Any suggestions will be appreciated, thanks!

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by QMESAR »

Hi,

I hardly use simulation so this is just a hint !
I am not sure if FC simulate UART or Interrupts correctly or at all.
I recall once I also had this issue and I then switched to HW and it is working fine ,Try HW

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by kersing »

Interrupts do not work in simulation.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

planeri
Posts: 11
Joined: Wed Aug 01, 2018 6:20 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by planeri »

Hi! I can assure that the interrupts that FC integrates by default work perfectly well in simulation. In fact, I just replaced the custom interrupt icon for a TMR1 standard icon and the program reaches the interrupt macro with no problems at all. What strikes me the most is that the information in the FC wiki in reference to custom interrupts suggests that it should be possible to simulate and even monitor them by using FC auxiliary variables.
QMESAR wrote:I recall once I also had this issue and I then switched to HW and it is working fine ,Try HW
I'll try that as soon as I can, thanks!

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: Using internal configuration registers & particular types of variables

Post by medelec35 »

I created a flowchart for someone that will allow a UART RX component read regally during simulation only, but then works as a normal UART RX interrupt in hardware only.
Not perfect but it does work.

Note that timer interrupts automatically get triggered during simulation (even if trigger on external pin is set).
Its UART interrupts that don't get triggered during simulation.
Martin

planeri
Posts: 11
Joined: Wed Aug 01, 2018 6:20 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by planeri »

Thanks for the replies, the UART RX interrupt example will surelly come in handy! I was trying a few things about the customized TMR1 interrupt, but I'm a little dissapointed at the fact that it can´t be properly simulated. For me, the posibility to simulate without the need to deploy to hardware is a key feature for professionals, and it would be great to be able to simulate custom code with access to internal configuration registers.

I attached the following files:
TMR1_INT_ex1.fcfx
(9 KiB) Downloaded 245 times
TMR1_INT_ex2.fcfx
(8.44 KiB) Downloaded 233 times
TMR1_INT_ex1.fcfx:

- TMR1 default interrupt with TMR1H/L initialization with custom C code icon.
- Interrupt works (simulation reaches Main_Loop macro), but there’s no real access to TMR1H/L values.
- The simulation triggers the following conversion messages:
“Statement “TMR1H = 0xCF” failed to convert: Does not correspond to a valid Flowcode assignment. TMR1H are not valid”

TMR1_INT_ex2.fcfx:

- TMR1 custom interrupt with enable and handle code. The handler code is added to function MX_INTERRUPT_MACRO().
- There are no conversion messages.
- Simulation never reaches Main_Loop macro.

Even with the first file I wasn't able to monitor the timer registers (TMR1H, TMR1L, T1CON) with the assistance of a FC variable via the component debugging window, as suggested in the FC8 wiki in the Custom Interrupts Timer1 Rollover example (https://www.matrixtsl.com/wiki/index.ph ... -_PICmicro).

planeri
Posts: 11
Joined: Wed Aug 01, 2018 6:20 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: Using internal configuration registers & particular types of variables

Post by planeri »

Well, I deployed my code to the PIC (TMR1_INT_ex1.fcfx with some extra code to make a buzzer sound every 10 seconds) with the custom TMR1 interrupt set to exactly 100 ms and it works perfect. It can also be simulated (despite the fact that you can't see the registers in the simulation debugger) to see how the interrupt routine works.
medelec35 wrote:I created a flowchart for someone that will allow a UART RX component read regally during simulation only, but then works as a normal UART RX interrupt in hardware only
I tried your code, excelent contribution! Do you have any experience with the vNet injector? I downloaded the example from the wiki (Node 1 and 2 from https://www.matrixtsl.com/wiki/index.ph ... 7bda03dc82) and tried to comunicate two simultaneous simulations, but I couldn't make it work. The TX node is working, but the character does not appear in the RX vNet window. Any ideas?

Some pics of the vNet TX and RX nodes running:

The TX node with the keyboard, every button pressed is sent to the TX vNet console via RS232:
TX_Console.JPG
TX_Console.JPG (62.26 KiB) Viewed 6827 times
The RX node is continuosly reading the UART device, but the RX vNet console is not receiving information:
RX_Console.JPG
RX_Console.JPG (57.57 KiB) Viewed 6827 times
The configuration used for the RX UART device (the injector is selected as data source for simulation):
RX_RS232_Conf.JPG
RX_RS232_Conf.JPG (42.31 KiB) Viewed 6827 times


Thanks everyone!

Post Reply