Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:06 29 Mar 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 : CMM2: V5.07.00b12 - Various fixes

     Page 9 of 9    
Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 01:30am 25 May 2021
Copy link to clipboard 
Print this post

@goc30,
The cmm2 needs the hobbytronics chip/module to use a usb mouse
A ps2 mouse can be used without any extra support.

You will not be able to use the mouse that belo gs to the keyboard

Jim
VK7JH
MMedit   MMBasic Help
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 425
Posted: 05:43pm 25 May 2021
Copy link to clipboard 
Print this post

  TassyJim said  @goc30,
The cmm2 needs the hobbytronics chip/module to use a usb mouse
A ps2 mouse can be used without any extra support.


Jim

I understood the functionning of the PS2 mouse. My question was just about knowing if for the CMM2, the presence of a wireless mouse could be a problem when using a PS2 mouse
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 07:02am 28 May 2021
Copy link to clipboard 
Print this post

The appears to be a bug in the DHT22 command.

I have tried various pins and 3.3V and 5V and different DHT22s.
The DHT22 is replying with good clean signals but most of the time the result is 1000, 1000

Occasionally, the checksum agrees and I get results that are impossible

When the DHT22 sent
0000001001110000000000001011100100101011
the results should be 18.5 degrees, 62.4%rh
Usually the CMM2 gives 1000, 1000 but on this occasion I got 9.2 deg 3308.3%rh

The bit sequence to produce those results is:
1000000100111011000000000101110000011000

Given that the two readings were a few seconds apart and the humidity would have changed slightly, it looks like the builtin command is inserting a leading "1"

Builtin cmd 1000000100111011000000000101110000011000
basic code   0000001001110000000000001011100100101011


I am not sure how long this bug has been there.

 DIM FLOAT te, hu
 DIM FLOAT tr(50,2)
 
 DIM INTEGER steps, alldone
 DIM INTEGER dht_pin = 28 ' 15 on the F4
 DO
   DHT22 dht_pin,te,hu
   PRINT te,hu
   PAUSE 2000
   dht11 dht_pin,te,hu
   PRINT te,hu
   PRINT
   PAUSE 5000
 LOOP
 
SUB dht11 pn, tem, hum
 LOCAL INTEGER n, x = 1
 LOCAL INTEGER repl(5)
 LOCAL reply$
 steps = 0
 alldone = 0
 FOR n = 0 TO 50
   tr(n,1) = 0
   tr(n,2) = 0
 NEXT n
 SETTICK 25, endtime,1
 PIN(pn) = 1
 SETPIN pn, DOUT, OC
 PAUSE 2
 PIN(pn) = 0
 PAUSE 1 ' this is the line that determines the start pulse length - 18 for the DHT11
 PIN(pn) = 1
 
 SETPIN pn, INTL, tick
 DO
 LOOP UNTIL alldone = 1
 SETTICK 0,1,1
 SETPIN pn, OFF
 FOR n = 1 TO 49
   IF tr(n+1,1)= 0 THEN EXIT FOR
   '  print  (tr(n+1,1)-tr(n,1))*1000, tr(n,1) ' this line gives the individual timings
   IF (tr(n+1,1)-tr(n,1)) > 0.1 THEN
     reply$ = reply$ +"1"
   ELSE
     reply$ = reply$ + "0"
   ENDIF
 NEXT n
 FOR n = 0 TO 4
   repl(n) = VAL("&b"+MID$(reply$,n*8+x,8))
 NEXT n
 hum = repl(0)*256+repl(1)
 'IF hum > 32767 THEN hum = hum - 65536
 hum = hum/10
 tem = repl(2)*256+repl(3)
 IF tem > 32767 THEN tem = tem - 65536
 tem = tem/10
 PRINT reply$
 PRINT repl(0),repl(1),repl(2),repl(3),repl(4)," ch_sum ";(repl(0)+repl(1)+repl(2)+repl(3)) AND 255
END SUB
 
SUB tick
 tr(steps,1) = TIMER
 steps = steps + 1
END SUB
 
SUB endtime
 alldone = 1
END SUB


Jim
VK7JH
MMedit   MMBasic Help
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3807
Posted: 08:49am 28 May 2021
Copy link to clipboard 
Print this post

As requested an alternative formulation for the STATIC variable bug reported previously:

400MHz Colour Maximite 2
MMBasic Version 5.07.00b33
Copyright 2011-2021 Geoff Graham
Copyright 2016-2021 Peter Mather

> list "static-bug.bas"
Option Explicit On
Option Default None
Option Base 0

If foo$("hello")         = "*hello*" Then Print "1: PASS" Else Print "1: FAIL"
If bar_1$("*hello*")     = "*hello*" Then Print "2: PASS" Else Print "2: FAIL"
If bar_1$("")            = "*hello*" Then Print "3: PASS" Else Print "3: FAIL"
If bar_2$(foo$("hello")) = "*hello*" Then Print "4: PASS" Else Print "4: FAIL"
If bar_2$("")            = "*hello*" Then Print "5: PASS" Else Print "5: FAIL"

Function foo$(a$)
 foo$ = "*" + a$ + "*"
End Function

Function bar_1$(b$)
 Static static_1$ = b$
 bar_1$ = static_1$
End Function

Function bar_2$(c$)
 Static static_2$ = c$
 bar_2$ = static_2$
End Function

> run "static-bug.bas"
1: PASS
2: PASS
3: PASS
4: PASS
5: FAIL


Note that all variables are UNIQUELY named, which should exclude any cause due to the re-use / shadowing of variable names.

Best wishes,

Tom
Edited 2021-05-28 18:51 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3641
Posted: 09:11am 28 May 2021
Copy link to clipboard 
Print this post

I'm very surprised that 3 prints PASS. I expected FAIL.

I would expect 5 to print FAIL.

My reasoning is that I would expect

Function anyfunc$(any$)
Static static_1$ = any$
...

to be the same as

Function anyfunc$(any$)
Static static_1$
static_1$ = any$
...

John
Edited 2021-05-28 19:11 by JohnS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3807
Posted: 09:29am 28 May 2021
Copy link to clipboard 
Print this post

Hi John

  JohnS said  I'm very surprised that 3 prints PASS. I expected FAIL ...


IMO you are confusing initialisation and assignment:
- in your first formulation you provide a value for the static during initialisation, something that happens only once for a static.
- in your second formulation you are just doing an assignment and a static can be assigned many times.

In C, which I *guess* the behaviour of STATIC is modelled on (may be a chicken & egg situation though):

#include "stdio.h"

int foo(int a) {
   return a + 1;
}

int bar_1(int b) {
   /* Slightly different formulation because you can't */
   /* initialise a static from a non-constant */
   static int static_1 = -1;
   if (static_1 == -1) static_1 = b;
   return static_1;
}

int bar_2(int c) {
   /* Slightly different formulation because you can't */
   /* initialise a static from a non-constant */
   static int static_2 = -1;
   if (static_2 == -1) static_2 = c;
   return static_2;
}

int main() {

   if (foo(10) == 11) {
       printf("1: PASS\n");
   } else {
       printf("1: FAIL\n");
   }

   if (bar_1(11) == 11) {
       printf("2: PASS\n");
   } else {
       printf("2: FAIL\n");
   }

   if (bar_1(0) == 11) {
       printf("3: PASS\n");
   } else {
       printf("3: FAIL\n");
   }

   if (bar_2(foo(10)) == 11) {
       printf("4: PASS\n");
   } else {
       printf("4: FAIL\n");
   }

   if (bar_2(0) == 11) {
       printf("5: PASS\n");
   } else {
       printf("5: FAIL\n");
   }
}

[thwill@PSEUK1383]$ cl "static.c"
Microsoft (R) C/C++ Optimizing Compiler Version 19.14.26433 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

static.c
Microsoft (R) Incremental Linker Version 14.14.26433.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:static.exe
static.obj
[thwill@PSEUK1383]$ ./static.exe
1: PASS
2: PASS
3: PASS
4: PASS
5: PASS


And before you say anything about the difference in formulation CMM2/MMBasic exhibits the reported bug given:

Function bar_1$(b$)
 Static static_1$ = "-1"
 If static_1$ = "-1" Then static_1$ = b$
 bar_1$ = static_1$
End Function

Function bar_2$(c$)
 Static static_2$ = "-1"
 If static_2$ = "-1" Then static_2$ = c$
 bar_2$ = static_2$
End Function


And nor is it string variable specific:

> list "static-bug.bas"
Option Explicit On
Option Default None
Option Base 0

If foo%(10)         = 11 Then Print "1: PASS" Else Print "1: FAIL"
If bar_1%(11)       = 11 Then Print "2: PASS" Else Print "2: FAIL"
If bar_1%(0)        = 11 Then Print "3: PASS" Else Print "3: FAIL"
If bar_2%(foo%(10)) = 11 Then Print "4: PASS" Else Print "4: FAIL"
If bar_2%(0)        = 11 Then Print "5: PASS" Else Print "5: FAIL"

Function foo%(a%)
 foo% = a% + 1
End Function

Function bar_1%(b%)
 Static static_1% = -1
 If static_1% = -1 Then static_1% = b%
 bar_1% = static_1%
End Function

Function bar_2%(c%)
 Static static_2% = -1
 If static_2% = -1 Then static_2% = c%
 bar_2% = static_2%
End Function

> run
1: PASS
2: PASS
3: PASS
4: PASS
5: FAIL


Best wishes,

Tom
Edited 2021-05-28 19:40 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3163
Posted: 09:43am 28 May 2021
Copy link to clipboard 
Print this post

Static static_1$ = any$
When you initialise a STATIC the initialiser is only used when the variable is created (on the first execution of the code) to set its initial value.  From then on the initialiser is ignored because the variable has already been created.

Static static_1$
static_1$ = any$

In this case, everytime the subroutine is executed the static variable will be set to the value of any$ overwriting whatever value the variable had retained from the previous execution.

I have not read the full thread so I hope that this post is not ignoring some previous post.

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

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3807
Posted: 09:45am 28 May 2021
Copy link to clipboard 
Print this post

  Geoffg said  Static static_1$ = any$
When you initialise a STATIC the initialiser is only used when the variable is created (on the first execution of the code) to set its initial value.  From then on the initialiser is ignored because the variable has already been created.

Static static_1$
static_1$ = any$

In this case, everytime the subroutine is executed the static variable will be set to the value of any$ overwriting whatever value the variable had retained from the previous execution.

I have not read the full thread so I hope that this post is not ignoring some previous post.

Geoff


Agreed, and the behaviour I would expect, the difference between initialisation of a static variable and assignment of a static variable.

EDIT: I would guess the bug is to do with the initialisation of a static variable from a parameter that is itself the "temporary" result of another function call.

Best wishes,

Tom
Edited 2021-05-28 19:48 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3641
Posted: 09:58am 28 May 2021
Copy link to clipboard 
Print this post

  thwill said  Hi John

  JohnS said  I'm very surprised that 3 prints PASS. I expected FAIL ...


IMO you are confusing initialisation and assignment:

Tom

No, I wasn't.

Rather, I'm surprised that it behaves (apart from the bug) the way it does in MMBasic.

Though Geoff has indicated it's supposed to do that (fair enough, I'll just stay surprised).

In which case you've found a bug I believe.

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 11:45am 28 May 2021
Copy link to clipboard 
Print this post

As requested an alternative formulation for the STATIC variable bug reported previously:


Same result on the latest development version of the firmware from Geoff on the MM2. Suggest you raise a new thread for a generic MMbasic bug
Edited 2021-05-28 21:47 by matherp
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3807
Posted: 11:56am 28 May 2021
Copy link to clipboard 
Print this post

  matherp said  
As requested an alternative formulation for the STATIC variable bug reported previously:


Same result on the latest development version of the firmware from Geoff on the MM2. Suggest you raise a new thread for a generic MMbasic bug


Thanks Peter, I have done as requested.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 04:04am 29 May 2021
Copy link to clipboard 
Print this post

Further to my bug report on the DHT22 code.
I think the CMM2 is too fast.
A short delay after the start pulse might be all that's needed to stop the rouge bit getting detected.
   // pulse the pin low for 1mS
   PinSetBit(pin, LATCLR);
   uSec(1000);
   PinSetBit(pin, LATSET);
   uSec(5); // *********  insert short delay here *********

   // wait for the DHT22 to pull the pin low and return it high then take it low again
   writeusclock(0);
   timeout = 400;
   while(PinRead(pin)) if(readusclock() > timeout) goto error_exit;
   while(!PinRead(pin)) if(readusclock() > timeout) goto error_exit;
   while(PinRead(pin)) if(readusclock() > timeout) goto error_exit;

   // now we wait for the pin to go high and measure how long it stays high (> 50uS is a one bit, < 50uS is a zero bit)
   for(r = i = 0; i < 40; i++) {


How much delay needs playing about with.

Jim
VK7JH
MMedit   MMBasic Help
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 07:04am 29 May 2021
Copy link to clipboard 
Print this post

  Quote  Further to my bug report on the DHT22 code.


I seem to have missed something - what is the issue?
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 07:15am 29 May 2021
Copy link to clipboard 
Print this post

  matherp said  
  Quote  Further to my bug report on the DHT22 code.


I seem to have missed something - what is the issue?


Towards the top of page 9.

The DHT22 code is inserting an extra "1" at the start of the bit sequence.
This means that I usually end up with an error but the occasional checksum works and I get a humidity of 3304% or similar.

My gut feeling is, the CMM2 is finding the initial start pulse as a valid bit because it is too fast in getting ready compared to all the other devices that use the same code.

Jim
VK7JH
MMedit   MMBasic Help
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 09:25am 29 May 2021
Copy link to clipboard 
Print this post

V5.07.00b36 now available

http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip

Should fix DHT22 although I haven't got a fully working module so testing is limited.

In addition now also supports the DHT11

New syntax:

DHT22 pin, temp!, humidity! [,version]


Valid codes for version are:
1 = DHT11
0 or omitted = DHT22
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 09:57am 29 May 2021
Copy link to clipboard 
Print this post

Working perfectly with the DHT22.
I don't have DHT11 to test

Many thanks as always.

Jim
VK7JH
MMedit   MMBasic Help
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1584
Posted: 06:48am 01 Jun 2021
Copy link to clipboard 
Print this post

Is there any chance of the new version V5.07.00 coming out soon?

I'd love to print the manual.

Bill
Keep safe. Live long and prosper.
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 323
Posted: 07:18am 01 Jun 2021
Copy link to clipboard 
Print this post

  thwill said  As requested an alternative formulation for the STATIC variable bug reported previously:

Note that all variables are UNIQUELY named, which should exclude any cause due to the re-use / shadowing of variable names.

Best wishes,

Tom


I'd think that since the static variable static_1$ had already been assigned "*hello* in the first call that subsequent calls to Function bar_1$ wouldn't be able to change it.

Try adding a PRINT. That may tell you what's happening:

Function bar_1$(b$)
Static static_1$ = b$
PRINT static_1$
bar_1$ = static_1$
End Function
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3807
Posted: 09:06am 01 Jun 2021
Copy link to clipboard 
Print this post

  toml_12953 said  I'd think that since the static variable static_1$ had already been assigned "*hello* in the first call that subsequent calls to Function bar_1$ wouldn't be able to change it ...


Thanks Tom, this has been moved into a different thread and Geoff has identified it as an MMBasic bug:

   http://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=13840

Note that whilst a static will only be initialised once, it can be (re)assigned multiple times.

The problem seems ostensibly to be something to do with initialisation from a function/sub parameter that was itself a "temporary" result (i.e not assigned to a variable) from another function, but it could well be more complex.

Best wishes,

Tom
Edited 2021-06-01 19:09 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 2989
Posted: 05:16pm 02 Jun 2021
Copy link to clipboard 
Print this post

Is the CMM2 port stable enough so that the lasted source can be made available on Geoff's page?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 9 of 9    
Print this page


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

© JAQ Software 2024