Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20563

BASCOM-AVR : using If statement with And statement : REPLY

$
0
0
Hello all, i got my program working, i'm surprise to find out what the issue was, although i honestly don't understand why this is. I changed the way i was getting the readings from the ADC, i had it configured to run in Free mode so i could use an interrupt and have the ADC get a reading everytime. I changed the settings from Free mode to Single mode and then just acquire a reading at the beginning of the loop, although this is not how i want to do it, but at least it works this way, the reason I wanted to use the ADC in Free mode is because i want to display the Pressure value on a GUI i made in Visual Studio, I want to be able to monitor the pressure constantly. So instead of using an interrupt to check for the ADC values i now start the ADC conversion at the beginning of the loop and when is done I stop the ADC, and continue with the Select Case code to check if the pressure is within the allowable range. I would like to see if someone can elaborate and educate me on why the way i previously had the code was not working. This is the code that works for me now! [code:1:db906ae9a5]Do Gosub Calculatep Ipressure = Pressure5 Disable Serial Print "Pressure levels " ; Iplow ; " " ; Iphigh Enable Serial Waitms 20 Select Case Ipressure Case Iplow To Iphigh Disable Serial Print "Pressure 5 " ; Ipressure Incr I Print "first" Enable Serial Shiftout Pinout , Srclk , Dataon , 1 Reset Portd.2 Set Rclk Waitms V Reset Rclk Shiftout Pinout , Srclk , Dataoff , 1 Set Portd.2 Set Rclk Waitms W Reset Rclk Disable Serial Print "Stroke Number 1" ; I ; " " ; "Pressure: " ; Pressure4 '; Chr(13); 'display current stroke number on hyperterminal Enable Serial Qualified = I Case Is > Iphigh Incr I Incr J Shiftout Pinout , Srclk , Dataon , 1 Reset Portd.2 Set Rclk Waitms V Reset Rclk Shiftout Pinout , Srclk , Dataoff , 1 Set Portd.2 Set Rclk Waitms W Reset Rclk Disable Serial Print "Stroke Number 2 " ; I ; " " ; "Pressure Is Higher: " '; Pressure4 ; Chr(13); 'display current stroke number on hyperterminal Enable Serial Unqualified3 = J Case Is < Iplow 'Elseif Pressure5 < Plow Then Incr I Incr H 'Print "third" Shiftout Pinout , Srclk , Dataon , 1 Reset Portd.2 Set Rclk Waitms V Reset Rclk 'On time set by W variable Shiftout Pinout , Srclk , Dataoff , 1 Set Portd.2 Set Rclk Waitms W Reset Rclk Disable Serial Print "Stroke Number 3 " ; I ; " " ; "Pressure Is Lower: " ; Pressure4 ; " " ; Iplow ; " " ; Iphigh 'display current stroke number on hyperterminal Enable Serial Unqualified4 = H 'End If End Select Totalstrokes = I Loop Until Buf = "terminate"[/code:1:db906ae9a5] and the subroutine that calculates the pressure is this: [code:1:db906ae9a5]Calculatep: Start Adc Pressure = Getadc(0) Voltage = Pressure / Fullrange Voltage1 = Voltage * Ref Pressure1 = Voltage1 - Intercept Pressure2 = Pressure1 / Slope Pressure3 = Pressure2 - Voltage4 Pressure4 = Fusing(pressure3 , "#.##") Pressure5 = Val(pressure4) Stop Adc Return[/code:1:db906ae9a5] Again thanks everyone for your support, hopefully someone can help me by explaining to me why it was not working before! Thanks, Walter

Viewing all articles
Browse latest Browse all 20563

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>