News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

It’s not clear.

Started by tolyan249, Today at 02:38 PM

Previous topic - Next topic

tolyan249

I wrote a program , it works, but I need to find the maximum number and output it from the right, The numbers change from the right, but not always, I can't figure out what the problem is, maybe someone will find an error ,
I posted the project. I can't find the problem that these conditions are not always met.

Random numbers appear there; he found the maximum number, which is 186. Then 480 came in, and for some reason it didn't move to the right, even though 480 is greater than 186. And it's like that everywhere. It's unclear.






' Output voltage - MAXIMUM
If OutputVoltage > OutputVoltageMAX Then
OutputVoltageMAX = OutputVoltage
EndIf

' Output current - MAXIMUM
If OutputCurrent > OutputCurrentMAX Then
OutputCurrentMAX = OutputCurrent
EndIf

PowerOutput = (OutputVoltage * OutputCurrent)

' Output power - MAXIMUM
If PowerOutput > PowerOutputMAX Then
PowerOutputMAX = PowerOutput
EndIf






Thank you.




RGV250

Hi,
Can you post a bit more detail as to what the issue is, also it might be easier if you could post a simpler code that can be simulated on an alphanumeric display.

Regards,
Bob

tolyan249

#2
I posted the project.

The problem is that when I run the program, random numbers are displayed on the left. The numbers on the right represent the maximum number encountered during the entire runtime. And the numbers on the right don't always change, even if the number on the left is greater than the one on the right. Finding the maximum number during the program's runtime.

The number on the left is larger, the one on the right is smaller.
And it didn't move to the right; then it came to 195 — he changed it to 195. But before that, it was 426, and for some reason he didn't change it.


The IF conditions aren't always met — if one number is greater than another, it means we should accept the larger number.


 
 
 Proc Update_Min_Max()
    ' Battery voltage - MINIMUM
    If BatteryVoltage < BatVoltageMIN Then
        BatVoltageMIN = BatteryVoltage
    EndIf
   
    ' Output voltage - MAXIMUM
    If OutputVoltage > OutputVoltageMAX Then
        OutputVoltageMAX = OutputVoltage
    EndIf
   
    ' Output current - MAXIMUM
    If OutputCurrent > OutputCurrentMAX Then
        OutputCurrentMAX = OutputCurrent
    EndIf
   

    PowerOutput = (OutputVoltage * OutputCurrent)
   
    ' Output power - MAXIMUM
    If PowerOutput > PowerOutputMAX Then
        PowerOutputMAX = PowerOutput
    EndIf
      
EndProc
 




trastikata

Quote from: tolyan249 on <strong>Today</strong> at 03:43 PMI posted the project.


It is hard to read an entire project, I doubt any one will be willing to spend that much time. Therefore:

- First do a procedure test - confirm "Proc Update_Min_Max()" works as expected - preload values to the variable, call the procedure and don't display anything but toggle a led. Something like Var1 = 10 : Var2 = 20 : If Var2 > VAr1 Then High Led : Else Low Led - do that for each If-Then statement.
- It is not easy to understand the exact behaviour from your explanation. Preload values (not random), display them and post pictures saying something like "Supposed to be 480" but I get this on screen ... and show the actual screen.
- Make sure it is not your display logic, but indeed the comparison - preload values and display - one after another in your program with a delay or hold button - this way you can know exactly what is happening - doing simulation with random numbers ad getting random problems can't correlate to anything unless you know the predicted and actual behaviour.

tolyan249

#4
https://protoncompiler.com/index.php/topic,3450.msg25188/topicseen.html#new
Maybe it's because of that?

It feels like IF can only compare bytes: if the number is less than 255, it becomes the maximum; if it's greater, it doesn't. All my variables are of the DWORD type.

tolyan249

I found the reason: the display itself leaves traces of the previous value and doesn't clear them. If the number was 195 and then 8 came in, it will show 895, because the number 1 took up the space, and the remainder of the previous number wasn't cleared.

I went through F10 and saw that there are no such numbers there — the ones the display showed.

Thank you, everyone.

▲