Analog_Pot_Uart

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
r_teixeir
Posts: 96
Joined: Fri Jul 15, 2016 10:51 am
Has thanked: 24 times
Been thanked: 5 times
Contact:

Analog_Pot_Uart

Post by r_teixeir »

Hi dear friends, Iam trying to code a program where I define a interrupt timer of 3ms, sampling a analog input reading and send through Uart. In simulation using flowcode the code works perfect and the variables change greatly. But when I Upload into the BL0032, the results look different in hardware compared to simulation. If somebody could help in any hint to solve this problem that would be great.

Thanks

Rod
Attachments
PROG_Test_Analog_Pot_Uart.fcfx
(16.76 KiB) Downloaded 91 times
Analog_Output_Pot.jpg
Analog_Output_Pot.jpg (85.25 KiB) Viewed 1949 times

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: Analog_Pot_Uart

Post by medelec35 »

Hi.
I had a look at your flowchart.
The interrupt component must be called only once, so it's best to place it before the main loop.
That is probably the issue of why you are just getting 0?
I would not recommend placing the Modulus function within an interrupt.
It better to use

Code: Select all

interrupt_cntrl = interrupt_cntrl + 1
If interrupt_cntrl = 300 then interrupt_cntrl = 0: seconds_counter = seconds_counter + 1
Martin

r_teixeir
Posts: 96
Joined: Fri Jul 15, 2016 10:51 am
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Analog_Pot_Uart

Post by r_teixeir »

Hi Martin thanks for replying. I corrected the place for the interrupt icon and it solved the problem about displaying values timer string. The problem now is that, the values for time string dont match what show on the simulation. I uploaded the the uart values, the analog is working but the timer should show an increment of 3,3ms for each sampling. Do you have any hints?

Thanks I appreciate

Rod
Attachments
Uart_Values_Display.jpg
Uart_Values_Display.jpg (100.18 KiB) Viewed 1897 times

r_teixeir
Posts: 96
Joined: Fri Jul 15, 2016 10:51 am
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Analog_Pot_Uart

Post by r_teixeir »

Hi Martin, I kept the same code for interrupt macro(The modulus) you've mentioned. Where do you insert that code you wrote? In a c code or the calculation flowchart? I tried to modified the code by not using the modulus, but the results in simulations were not what I wanted because it does not increment one of the variables that gives info about when it reaches 1 sec. If you run my code in simulation you'll see the increment from 3.3ms so on and when it reaches 1s you may see the variable incrementing to 1, which is one of the things I want to.

Thanks

Rod

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: Analog_Pot_Uart

Post by medelec35 »

Hi Rod,
For your flowchart to do what you want, It looks like the modulus is the way to go since you have not got any other modulus functions in your flowchart, except for the timer interrupt.
If you did have modulus functions in other user macros, including main, then to avoid corruption, an alternative would be to use:
Modulus Alternative.png
Modulus Alternative.png (39.34 KiB) Viewed 1883 times
Which is the modulus equivalent.
I the value used is a power of 2 rather than 300, then bit-shifting would make it more efficient.

So, with your flowchart, if the timer interrupt is moved to above the main loop, it should hopefully work the way it's intended to?
Martin

Post Reply