Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 07:15 30 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Select Case...

Author Message
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 24
Posted: 08:30pm 15 Jan 2016
Copy link to clipboard 
Print this post

Hello all,

I'm having trouble getting my SELECT CASE script to do what I want (maybe it can't do it anyway!).

I have SETPIN 2 (and 3), DOUT
DDD%=64


select case DDD%
case is <32
port(14,5)=DDD%
case is >=32, is <64
pin(2)=1
'ARMDIS%=1 'DEBUG
port(14,5)=(DDD%-32)
case is >=64, is <128
pin(3)=1
pin(2)=1
'ARMDIS%=1 'DEBUG
'OTHER1%=1 'DEBUG
port(14,5)=(DDD%-96)


I'm expecting pins 2 & 3 to go high, but only pin 2 does.
There is a CASE ELSE and END SELECT as well.
The whole script runs without errors, but pin 3 does not go high, as measured by multimeter.
Any thoughts?

EDIT
I am running MMII (170) with 4.06 (4.6b) and have tried a second 'mite.
Thanks,
gregEdited by expo 2016-01-17
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 09:14pm 15 Jan 2016
Copy link to clipboard 
Print this post

@ expo

try 64 to 128 instead of
case is >=64, is <128

Mike
Codenquilts
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 24
Posted: 09:22pm 15 Jan 2016
Copy link to clipboard 
Print this post

Thanks for the suggestion MikeO but it didn't change the output. Pin 3 still remains off.
greg
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 09:36pm 15 Jan 2016
Copy link to clipboard 
Print this post

@expo

First of all, can you inform us which version of MMBasic; and what type of MicroMite?

Also, some things to quickly try:

1> Check Pin(3) LED is ok. Issue a PIN(3)=1 command at the command prompt to ensure electrical connectivity (and hardware) is ok

2> Drop the 'IS' and change to >63 rather than >=64 (in case of firmware bug)

WW



For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 24
Posted: 10:04pm 15 Jan 2016
Copy link to clipboard 
Print this post

Hello WW,

I have tried MikeO's suggested "64 to 127", but there was no change.
I tried your suggestion ">63, <128", but no luck there either.
After the thought process from you both I tried "63<DDD%<128", - no banana either.

I am using MMII (170) 28 pinner, MMBasic 4.6, MMEdit 3.6.4 OS Ver10 (14/9/15).

I have been measuring the output at the MMII pin to avoid spurious extraneous hardware faults.

Can anyone replicate this fault or confirm their system works OK?

greg
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 24
Posted: 10:18pm 15 Jan 2016
Copy link to clipboard 
Print this post

Hello MikeO and WW (and other watchers),

I think I have an issue wit resetting the pins when DDD% changes downwards.

Stay tuned whilst I work on it .... sometime!

Thanks for your review and the time to respond. I will post any enlightenment.

greg
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:19pm 15 Jan 2016
Copy link to clipboard 
Print this post

@expo

And have you confirmed that PIN(3)=1 turns on the LED? Or are you saying that you have no LEDs connected and are just using a multimeter?

Is the 28pinner mounted on a breadboard? If so, ensure you measure the voltage directly on the PIC pin 3 and not a position connected to pin 3 via the breadboard. If you're not aware, there have been many posts about issues for people using breadboards, and these always turn out to be 'faulty' (cheap) breadboards.

keep us informed with progress . . . .

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:22pm 15 Jan 2016
Copy link to clipboard 
Print this post

Yes, maybe a negative ddd% causes the issue!

You're checking for: 64 <= DDD% < 128 and if so, subtracting 96 from it and setting pins to potentially a negative value of DDD%.

Is this the issue maybe??
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 01:52am 16 Jan 2016
Copy link to clipboard 
Print this post

Without decoding the program logic the problem could be caused by the fact that the expressions on the CASE line are ORed.

For example,
CASE 1, 2, 3
will be true if the test number is 1 -or- 2 -or- 3

So
case is >=32, is <64
Will be always true because the test number will always be greater than 32 -or- less than 64.

I should update the documentation to clarify this.

Geoff
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5905
Posted: 10:24am 16 Jan 2016
Copy link to clipboard 
Print this post

DDD% = 64

SELECT CASE DDD%
CASE IS <32
print "<32"
CASE IS <64
print ">=32 and <64"
CASE IS <128
print ">=64 and <128"
CASE ELSE
print ">=128"
END SELECT


There is no need to test for >=32 etc because is the first test for 'less than' passes, the remainder of the SELECT statement is ignored.

Jim

VK7JH
MMedit   MMBasic Help
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:31am 16 Jan 2016
Copy link to clipboard 
Print this post

I am curious as to why LED on Pin 3 is not coming on when DDD%=64 (i.e. the posted issue).

The code originally posted should turn it on shouldn't it??

TassyJim: Your code is the 'tidy' solution in terms of coding but can you see why Pin 3 won't go high in expo's code?

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 10:32am 16 Jan 2016
Copy link to clipboard 
Print this post

Also - what happens if your use the PORT command with a negative number (as it would be when DDD%=64)?

Does MMBasic generate an error message? OR is the value ignored? Or is it outputted as two's complement?

I am not with a MM at hand at the moment so can not try this one just now.Edited by WhiteWizzard 2016-01-17
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5905
Posted: 10:46am 16 Jan 2016
Copy link to clipboard 
Print this post

The line
case is >=32, is <64

will be the one executed when DDD% = 64 because as Geoff pointed out, the comma is an OR not AND

This sets PIN 2 high

The CASE with PIN 2 and PIN 3 high never gets acted on because of the line above getting first choice.

Jim
VK7JH
MMedit   MMBasic Help
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 11:11am 16 Jan 2016
Copy link to clipboard 
Print this post

Yep - silly me
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 24
Posted: 12:06pm 16 Jan 2016
Copy link to clipboard 
Print this post

Hello all,

CASE = 64 does turn on pins 2 & 3. Any other combination of <, >, <=, etc fails because as Geoff has clarified they are -OR-'d.

In the short term I will abandon use of SELECT CASE because it overly complicates my logic (and me!).

PORT(14,5)=DDD% works well, so I will work around the higher numbers another way.

Thanks to all for your efforts.

greg
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024