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
Analog_Pot_Uart
Moderator: Benj
-
- Posts: 96
- Joined: Fri Jul 15, 2016 10:51 am
- Has thanked: 24 times
- Been thanked: 5 times
- Contact:
Analog_Pot_Uart
- Attachments
-
- PROG_Test_Analog_Pot_Uart.fcfx
- (16.76 KiB) Downloaded 100 times
-
- Analog_Output_Pot.jpg (85.25 KiB) Viewed 2429 times
-
- 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
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
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
-
- Posts: 96
- Joined: Fri Jul 15, 2016 10:51 am
- Has thanked: 24 times
- Been thanked: 5 times
- Contact:
Re: Analog_Pot_Uart
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
Thanks I appreciate
Rod
- Attachments
-
- Uart_Values_Display.jpg (100.18 KiB) Viewed 2377 times
-
- Posts: 96
- Joined: Fri Jul 15, 2016 10:51 am
- Has thanked: 24 times
- Been thanked: 5 times
- Contact:
Re: Analog_Pot_Uart
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
Thanks
Rod
-
- 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
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: 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?
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: 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