Sunday, 22 April 2012

VSM and i2c: Beware

Why are companies so reluctant to tell you what their products won't do?


The Picaxe VSM simulator is a great product if it simulates the functions that you want to use. The problem is that it is sold by Revolution Education with broad claims - ie that it will do simulation "for all M, X, X1, X2 PICAXE chips" and "Support for all major protocols, including RS232, spi, i2c, 1-wire, etc."


But - after investing five or six hours learning my way around VSM (which provides reasonable-but-not-brilliant documentation and limited tutorials, but still involves a big learning curve) - I hit problems with an i2c interaction between two 20x2 Picaxe chips not working as I expected.


So I reduced everything to the absolute basic, with one chip acting as Master, trying to update a single byte on the other, set up as Slave.


It failed - and there in the log (as an item of Information, not an Error) was the message:
Background i2c receive (slave mode) cannot be simulated


I've googled for workarounds or updates - and there are none. So everything points to this being a fundamental limitation of the VSM simulation program as supplied by Revolution Education.


I don't expect the world for sixpence - but I do think it would be rather more grown-up for companies selling products that have known limitations to treat their potential customers like adults and say "This product does all these brilliant things, but please be aware before you buy it that it won't do the following".


UPDATE 23 April 2012


Reply from Picaxe Technical Support:


The current PICAXE X2 VSM models have only been recently added, are in beta state and therefore don't support all that a physical PICAXE may offer; I2C master mode is supported but I2C slave mode currently is not. I2C slave emulation is quite complicated (effectively a whole different model to layer on top) and we do not currently have an estimate as to when that may be supported. 



Saturday, 21 April 2012

VSM and the AXE033 display


My first test of the VSM simulator didn't go well - I tried to output a simple text message from a 20x2 to an AXE033 LCD component, and nothing happened.


For once, a quick Google sent me in nearly the right direction, and a bit of trial and error got it sorted soon afterwards


Key points:

  • Despite a 2008 promise on the Forum to provide improvements, the VSM will still (in 2012) only write to the AXE033 at T2400 (or T2400_8 if frequency is at m8, eg 20x2)
  • If you are writing to the AXE033 as the first thing your program does, you may need to add a delay: in my case 150 milliseconds is enough: a bit less gets you part of the string, and no pause results in no string!
Here is a program to run on a 20x2 with an AXE033 connected to pin C.0:




'test program to get 033 LCD working 
#define forVSM




#ifdef forVSM
symbol baudRate=T2400_8 'for VSM
#else
symbol baudRate=N2400_8 'for physical chip
#endif


symbol pinForDisplay=C.0




#ifdef forVSM

#rem
VSM needs 150 milliseconds (in my configuration) before it can write to the LCD/OLED. 
This is only needed if writing at the very start of the program, 
so if your LCD/OLED write happens at least 150 msecs after program starts
then you won't need this
You can try a shorter pause (eg 120) - in my case I only got the end of the string displayed


#endrem
pause 150
#endif


serout pinForDisplay,baudRate,(254,1) 'clear screen
pause 30 'give screen clear time to execute


serout pinForDisplay,baudRate,(254,128) 'go to start of line 1
serout pinForDisplay,baudRate,("0123456789abcdef")


serout pinForDisplay,baudRate,(254,192) 'go to start of line 2
serout pinForDisplay,baudRate,("fedcba9876543210")

Sunday, 1 April 2012

Timer and settimer

There's a lot of detail on settimer in the manual, but I still struggled how to reset the timer. In fact it is blindlingly obvious:

timer=0

timer is just a word variable, which gets incremented when a second (hidden) "minor tick" variable overflows. The preload value in settimer specifies what value the "minor tick" counter moves to once it has hit 65535: the higher the preload value, the fewer increments needed, and so the sooner the "minor tick" overflows and increments timer.

The pitfall is that wheras the first settimer command will set the timer to zero, any subsequent settimer commands will change the rate at which the timer increments, but will NOT reset the timer

Saturday, 31 March 2012

If you mean PAUSE don't write WAIT

Be careful with the wait command.

I used one in error (I meant pause). And the consequences were more than just waiting 1000 times as long as I had intended (wait counts in seconds, pause counts in microseconds).

With wait in my coding, my 20x2 wouldn't program. Not only wouldn't it program, but it wouldn't re-program with any other program. I thought I had "bricked" the chip.

Luckily, I found instructions on how to tackle a chip that won't reprogram: remove the 5v lead, start the programming process, wait one or two seconds, then replace the 5v. If that doesn't work, remove all the other connections to the chip (except for the 0v, Serial In and Serial Out) and try again: I was getting a voltage on the 5v pin with no power connected, but with a 5v feed to pin C.1.

Once I removed the wait command, the chip would reprogram normally.

Tuesday, 20 March 2012

Long-cable connection between Picaxe Units

Found at last - what looks like a reliable, flexible, and economical way of linking Picaxe chips over considerable distances of Cat5 cable.

The answer is to use a P82B96 IC at each end of the run:


The P82B96 is available as a DIP8 costing less than a 20x2 in the UK (I used RS online). Using the i2cslow_8 setting, I have managed 300m with just a simple master-slave pair. Adding a second slave (simply teeing off from the two twisted pairs) saw the system fail on a 300m length, but it is fine on a 100m length (I don't have any lengths in between to test with).

Don't forget the pull-up resistors on SCL and SDA on both master and slave (10k worked for me)!

Source of the 12v circuitry is here - see Figure 4

Hope this helps someone.

Monday, 12 March 2012

Superscript dots on AXE133Y (and probably AXE134Y) OLED/LCD

Suddenly found superscript dots (same size as full-stop/period) in the display on an OLED using AXE133Y - and eventually found the explanation: it is the result of outputting an empty string, eg:
  serout pinOLEDdisplay,oledSpeed,("")

Not terribly useful, as it still uses up one character - but at least it isn't anything more significant.

Sunday, 4 March 2012

Problems with hi2cIn or hi2Cout?

Took me a while to spot that with syntax such as:

HI2CIN [newslave],location,(variable,...)

the square brackets DO NOT mean that the variable is optional (which you might guess, given that this is the nomenclature often used in computer manuals). It means that you literally type the square brackets around the value

Thus :

HI2CIN [%10010010],0,(122,154)