How to map pins to symbols?

codeOwl

New Member
Hi there,
I am writing a program to run on the PICAXE 14M2, however I want to simulate the circuit in PICAXE VSM first, and as it doesn't support the 14M2 yet, and the 14M doesn't have any pwm pins, so I need to use the 28X1 for the simulation. So now I am writing a program to run on the 28X1. First thing I want to do is set-up symbols that map the the pins and then use these throughout the program, so to make it run on the 14M2 once I have it working correctly in the simulation, I can just change the pins that the symbols map to.

I am just starting to learn how to work with electronics, but have a background in C#. I have written some simple programs for the picaxe using the 08M, flashing LEDs, reading potentiometer values, and reacting to switchs etc...

I have read the documentation (eg; page 34 of picaxe_manual1.pdf) that gives the PICAXE-28X2/28X1/28X/28A Pinout.

I want to:
- Read a potentiometer value into leg 2 (pin a0)
- Read a potentiometer value into leg 3 (pin a1)
- A switch is connected to leg 15 (pin c4) and I want to check if this is low or high
- A switch is connected to leg 16 (pin c5) and I want to check if this is low or high
- Run pwm out leg 12 (pin c1)
- Run pwm out leg 13 (pin c2)

I have tried the following code and get the following error:
symbol _MotorForwardPWMPin = c1
^
Error: Unknown symbol - c1

What is the correct syntax to map these pins to symbols?

I can't seem to find any doco that tells me how to do it for the 28X1.

Thankyou for your time,

codeOwl
 

MartinM57

Moderator
Short answer...
Code:
symbol _MotorForwardPWMPin = c.1
..so that you can then do, for example
Code:
pwmout _MotorForwardPWMPin, 10, 100
Long answer...no doubt someone will come along to give chapter and verse on symbols and pins :)
 

westaust55

Moderator
And for the potentiometer notingh that the 14M2 only has ports B and C no port A:

readadc C.0, b1

or

SYMBOL potent = C.0
READADC potent, b1

For your switches:

SYMBOL switch1 = pinC.4
IF switch1 = 1 THEN
b5 = 99
ELSE
b5 = 77
ENDIF

Note the format is port.pin
 
Last edited:

hippy

Ex-Staff (retired)
It's also possible to use conditional compilation so you can run the code on either 14M2 or 28X1 with the right SYMBOL definitions for each, and to overcome other differences in the main program code, for example ...

Code:
#IfNDef 28X1
  #IfNDef 14M2
    #Error "This code only runs on a 28X1 or 14M2"
  #EndIf
#EndIf

#IfDef 28X1
  Symbol SPEED_POT = 1
#EndIf

#IfDef 14M2
  Symbol SPEED_POT = C.1
#EndIf
 

codeOwl

New Member
Short answer...
Code:
symbol _MotorForwardPWMPin = c.1
..so that you can then do, for example
Code:
pwmout _MotorForwardPWMPin, 10, 100
Long answer...no doubt someone will come along to give chapter and verse on symbols and pins :)
Martin,
Thanks for the super fast reply mate. However c.1 doesn't seem to work. I get the following error:

symbol _MotorForwardPWMPin = c.1
^
Error: Unknown symbol - c.1

I also tried it with a capital C as well, but just got the same error. I think the C.1 type names are only for the new M2/X2 type chips. Page 34 of the manual:
http://www.picaxe.com/docs/picaxe_manual1.pdf
shows that the 28X2 has C.0, C.1 etc... but the 28X1 has c0, c1 etc...
However I can not get either of these to work, with the PICAXE 28X1.
I have have the PICAXE Program Editor options set to the mode:
PICAXE 28X1/40X1
and I get this error when I press the Syntax checker button.
This is the issue I have, in the manual there are code samples for how to reference the M type chips and the M2 type chips, but not the X1 type chips.

Regards,

codeOwl
 

codeOwl

New Member
And for the potentiometer notingh that the 14M2 only has ports B and C no port A:

readadc C.0, b1

or

SYMBOL potent = C.0
READADC potent, b1

For your switches:

SYMBOL switch1 = pinC.4
IF switch1 = 1 THEN
b5 = 99
ELSE
b5 = 77
ENDIF

Note the format is port.pin
Westaust55,

Thanks for the reply mate. Please see my post to reply to Martin, for what happened when I tried the C.1 naming format.

Regards,

codeOwl
 

codeOwl

New Member
It's also possible to use conditional compilation so you can run the code on either 14M2 or 28X1 with the right SYMBOL definitions for each, and to overcome other differences in the main program code, for example ...

Code:
#IfNDef 28X1
  #IfNDef 14M2
    #Error "This code only runs on a 28X1 or 14M2"
  #EndIf
#EndIf

#IfDef 28X1
  Symbol SPEED_POT = 1
#EndIf

#IfDef 14M2
  Symbol SPEED_POT = C.1
#EndIf
Hippy,

Thanks for the reply. The #IfDef logic is a great tip! Unfortunately the C.1 naming format didn't seem to work. Please see my reply to Martin for details on this.

Regards,

codeOwl
 

eclectic

Moderator
Can't help more at the moment, but
Code:
#picaxe 28X1
high portc 1
 
symbol MotorForwardPWMPin = portc 1
The high portc 1 passes syntax.
However the
portc 1 fails

See M.2, p.84

e
 

Technical

Technical Support
Staff member
On the old 28X1 in the command line

high portc 1

the 'high portc' is actually the command. Hence you can't rename 'portc 1', as 'portc' is actually part of the command, not the pin numbering.

So the best you can do on the 28X1 part is

symbol motorForwardPWMPin = 1
high portc motorForwardPWMpin
 

Morrolan

New Member
Apologies, seems I mis-read your requirement and was trying to give you M2 based code.
I think part of the problem is he wants to test 14M2 code on the VSM which doesn't support the 14M2 yet, hence using the 28X1 for testing. I think the confusion is setting in here because of the differences between an M2 and an X1.
 

hippy

Ex-Staff (retired)
I think the confusion is setting in here because of the differences between an M2 and an X1.
One option may be forget the 14M2 for now, develop the VSM code for the 28X1 and then use the Programming Editor Convert to X2 Wizard to turn the 28X1 code into 28X2 code, and edit that to be used with the 14M2.

The wizard converts -

#Picaxe 28X1

Symbol MY_PIN = 1

High PortC MY_PIN
With a litle post editing applied to -

#picaxe 28x2

let dirsB = %11111111

Symbol MY_PIN = C.1

High MY_PIN
 

codeOwl

New Member
Thank you all for your input, it is much appreciated. It is a great community here :) I have decided to abandon PICAXE VSM for this project. It is a great tool with great potential, however with no support for the current chips and other issues such as the pwm pin off command not being supported, it is very limited.
http://www.picaxeforum.co.uk/showthread.php?17559-Errors-using-PWMOUT-in-VSM&highlight=pwmout
http://www.picaxeforum.co.uk/showthread.php?19820-pwmout-2-off-using-08M-gives-syntax-error-in-VSM
I have found it great for designing the circuit but there have been other issues which make it counter productive. Breakpoints continuing to get hit after I disable them etc...

So I have written the program for the 14M2 and will attempt to test/debug it on the board. I have the AXE091U.

One thing I was looking for in the debug window of the PICAXE Programming Editor was, I can see outputpinsB and outputpinsC, but can not see anywhere that shows the high/low state of inputpins. I want to see the high/low state of pins so when I press a button wired up to a pin, I can see it's state change in real-time while debugging. Is there a way to do this with the PICAXE Programming Editor debug functionality?

Thanks for you time,

codeOwl
 

Morrolan

New Member
Yes you can - if you set the output high or low in code, the green coloured pin label lights up - if you're monitoring input pins, it again shows the high and low state.

Another option is to throw serial data at the terminal using the 'sertxd' command. I use it mostly as a custom debugging output, commands look like:

Code:
sertxd "Pin 1 = ", bit0
That will output:

Pin 1 = 1

This obviously relies on you doing "let b0 = b.1" somewhere before the sertxd command to actually assign the state of pin b.1 to a variable. There are other ways to achieve this by reading all pins at once but in my opinion it's easier to understand by explicitly stating which pins you want before delving into that.
 

codeOwl

New Member
Morrolan,

Thanks for the reply mate and thanks for that tip on the 'sertxd' command, that is great!

Yes you can - if you set the output high or low in code, the green colored pin label lights up - if you're monitoring input pins, it again shows the high and low state.
Would I be right in thinking that, you are talking about the simulator here, and this will be great to test the logic of the code, but no good to test the logic of the circuit, as the simulator does not interface with the physical chip/circuit.

But that is where the 'sertxd' command comes in, by reading a pin value into a variable and use the 'sertxd' command in my code and downloading it to the chip, it will spit the value back out from the chip to the terminal window.

It seems however, that I can only be either, debugging and have the debug window show, or have the terminal window show. I can't have both running at once as they are modal dialogues. Is this correct? Or is there a way to have both running at once?

Thanks for your time,

codeOwl
 
Last edited:

hippy

Ex-Staff (retired)
It seems however, that I can only be either, debugging and have the debug window show, or have the terminal window show. I can't have both running at once as they are modal dialogues. Is this correct? Or is there a way to have both running at once?
That is correct; it's one or the other though it's possible to have both SERTXD and DEBUG commands in a single program and close/open debug and terminal displays as desired - that might get a bit messy in the terminal display.

When running code in a PICAXE chip, and using SERTXD or DEBUG, the debugging information is only sent when the respective command is executed, not all the time so a "DO:LOOP" for example won't update either display no matter how your inputs are changing.

On an M2 and using multi-tasking you could add a "Start1: DO:DEBUG:LOOP" line which would give an almost a continuous update no matter what other tasks were doing but it might not be appropriate to run the chip in that way depending on what you are doing.

It's also not easy to tell which DEBUG command is being executed if you have more than one so using SERTXD can be better as it can indicate which SERTXD it is and it can supply only the specific data you are interested in seeing for where the code is ...

SerTxd( "Entering wait loop", CR, LF )
Do : Loop Until pinC.1 = 1
SerTxd( "Exited wait loop (C.1=1)", CR, LF )
 

codeOwl

New Member
That is correct; it's one or the other though it's possible to have both SERTXD and DEBUG commands in a single program and close/open debug and terminal displays as desired - that might get a bit messy in the terminal display.

When running code in a PICAXE chip, and using SERTXD or DEBUG, the debugging information is only sent when the respective command is executed, not all the time so a "DO:LOOP" for example won't update either display no matter how your inputs are changing.

On an M2 and using multi-tasking you could add a "Start1: DO:DEBUG:LOOP" line which would give an almost a continuous update no matter what other tasks were doing but it might not be appropriate to run the chip in that way depending on what you are doing.

It's also not easy to tell which DEBUG command is being executed if you have more than one so using SERTXD can be better as it can indicate which SERTXD it is and it can supply only the specific data you are interested in seeing for where the code is ...

SerTxd( "Entering wait loop", CR, LF )
Do : Loop Until pinC.1 = 1
SerTxd( "Exited wait loop (C.1=1)", CR, LF )
Hippy,

Thanks for the response mate. Reminds me of programming in JavaScript eg; alert('we made it this far')... :)

I had a go at the SerTxd command as suggested and I found that when doing a simulation it worked fantastic:


But after downloading the code to the chip, and then looking at the Terminal Window, there was no output, until I press the switch, and then I got these weird characters:


Any ideas what am I doing wrong mate?

Thanks again for your time,

codeOwl
 

codeOwl

New Member
Try playing with the baud rate radio button - start with 9600 and then go either side etc
Martin,

Thanks for the tip mate. I tried every option and the best I got was this:


I guess this is ok, as long as I can read the message from the SerTxd command. Is this normally how it looks for everyone else, with all this other junk in there?

Thanks for your time,

codeOwl
 

codeOwl

New Member
Hippy,
Thanks for you help mate. Much appreciated!! I have been able to resolve the issue I had using the serial debug method.

Thanks again to all contributed!!

Regards,

codeOwl
 
Top