![]() |
Forum Index : Microcontroller and PC projects : Multi-pin OR problem.....
Author | Message | ||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
Hello. ![]() I have an issue here where I need to check TWO pins on a battery charger module - CHG and STBY. The pins are setup as inputs. The code has to check both pins as part of an OR to see if the pins are in one of two states. This is not working, even though testing of the pins at the command prompt under both states does reflect what should be going on. TRUTH TABLE: CHG STBY FUNCTION ----------------------------- 0 0 Not on charger 0 1 Charging 1 0 Standby(charging finished. Only while ON charger) 1 1 (never happens) Screenshot of my querying MMBASIC directly at the console: ![]() The first query is while the unit is on charge, the second query is after the charging is complete. You will see that this agrees with the table above. But the problem is that when PIN(CHG)=1 and PIN(STBY)=0, the loop is NOT exiting to the next line. The charger has finished charging, but my code keeps on fading the red LED in and out indicating it is still charging. The LED should go BLUE when the charger module indicates the charging is complete. This does not happen, even though the pins are in the correct state. The second part of the OR is if both pins are now zero. That means the charger has had its power removed - the unit has been unplugged from the charger. Here is the full charging loop code: Can anyone help me understand why this is not working as expected? IE: When pins CHG and STBY are 1 and 0 respectively, OR 0 and 0 respectively, the loop should exit - it does not when CHG is 1 and STBY is zero, but it DOES if I pull out the charger, and then both pins are zero. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
erbp Senior Member ![]() Joined: 03/05/2016 Location: AustraliaPosts: 195 |
deleted - didn't look close enough at the posted code ![]() Edited 2019-09-23 11:26 by erbp |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1114 |
G, I can't see anything wrong (but that doesn't mean a lot ![]() I would also take the watchdog out temporarily so there is no restart happening somewhere. I assume the leds are fading as required? If Pin(CHG)=0 and PIN(STBY)=1 Then '**** print "On entry, Charge ",Pin(Chg),"Stby ",pin(Stby) '**** BFLAG=0 'Clear battery flag now we are back on the charger Print "Charging battery." Do For X=1 To 100 'Fade up red LED PWM 1,100,0,X,0 'Green/Blue/Red on 1A/1B/1C Pause 2 Next Pause 250 'Small delay before fading down For X=100 To 0 Step -1 'Fade down red LED PWM 1,100,0,X,0 Pause 2 Next Pause 250 'Small delay before fading up Watchdog 10000 Loop Until (pin(CHG)=1 and pin(STBY)=0) OR (pin(CHG)=0 and Pin(STBY)=0) 'Do this till charging finished '**** print "On exit, Charge ",Pin(Chg),"Stby ",pin(Stby) '**** PWM 1,STOP 'Stop PWM channel for LED fading If Pin(CHG)=1 and PIN(STBY)=0 THEN SetPin RLED,DOUT:SetPin GLED,DOUT:SetPin BLED,DOUT 'Reset LED pins Pin(RLED)=0:Pin(GLED)=0:Pin(BLED)=1 'Fully charged. Print "Charging cycle complete." panky. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
We are missing the ENDIF's to follow the program but your test condition can be simplified The second line is functionally the same and easier to follow. I prefer to do something like this: but it depends on the rest of the program. VK7JH MMedit |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
Jim Is spot on above (as usual). There is another way... using the Port function returns an absolute value: Select Case Port(CHG,1,STBY,1) Case 0 ' both pins 0 Case 1 ' only CHG is hi Case 2 ' only STBY is hi Case 3 ' both pins hi End Select jus' sayin' Edited 2019-09-23 15:24 by CaptainBoing |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
Excellent ideas, thanks very much chums. I like the port idea, and had never even considered that! So simple, and should simplify things. This gives me several things to try out. Thanks again. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
Cyber![]() Senior Member ![]() Joined: 13/01/2019 Location: UkrainePosts: 161 |
Grogster, have you solved the problem? I'm intersted to know. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
I have not had a chance to play with this in the last few days, but I am hopeful the SELECT CASE idea will work. I will try to play with this idea soon. I will let the thread know what happens. Are you having a similar issue? Smoke makes things work. When the smoke gets out, it stops! |
||||
Cyber![]() Senior Member ![]() Joined: 13/01/2019 Location: UkrainePosts: 161 |
Not really. I'm just starting my way into electronics, and I'm interested following the thread. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |