20M2 Conflicts

erco

Senior Member
I just built a 20M2 board and I'm getting some kind of conflict. Running three servos with servo command on B.3 B.4, B.5, and using an ADC on B.6. Servo on B.4 (only) shuts down when I use sertxd to display the ADC output. When I comment out the sertxd, servo on B.4 works fine. Anybody know what's going on?

Code:
#picaxe 20m2
#no_data
#terminal 4800 

fvrsetup FVR4096 ; set FVR as 4.096 V
adcconfig %011 ; set FVR as ADC Vref+, 0V Vref-
pause 500			' initialize on powerup

servo B.5,140 'ping servo center=140   70=full ccw 230=full cw  
servo B.4,162 'left servo null=142    fwd=162   rev=122
servo B.3,125 'right servo null=145   fwd=125  rev=165 was 3

aa:readadc b.6,w1
sertxd(#w1,13,10)
goto aa
 

erco

Senior Member
Putting a nice long PAUSE 500 after sertxd got all my servos going again. There was noticeable servo stuttering at PAUSE 100, but not at 500. I can live with slower serial output for now, but I welcome any input from the collegium.
 

Technical

Technical Support
Staff member
The sertxd temporarily suspends the background servo pulses (to avoid corrupting the serial data) and so any servo may be affected, it was just a loop timing coincidence that one appears to work whilst the other doesn't.
 

westaust55

Moderator
@erco,
a read of Appendix 4 on page 268 of PICAXE manual 2 will also shed some light on the conflicts that may/will arise between various BASIC commands.
 

inglewoodpete

Senior Member
The way around the problem is to use the hSerOut pin for your Serial Outputs (ADC data). Being a hardware USART, it does not rely on software timers to clock out the serial data. If you're lucky, you will have pin C.0 free for hSerOut use:). If you go down this path, pay attention to bit 4 of the hSerSetup mode parameter.
 

techElder

Well-known member
It was quite obvious that your current program was so simple that it only took one large champagne to finish it.

Great! So now we have a new way to measure programming skills! ;)
 

erco

Senior Member
The way around the problem is to use the hSerOut pin for your Serial Outputs (ADC data). Being a hardware USART, it does not rely on software timers to clock out the serial data. If you're lucky, you will have pin C.0 free for hSerOut use:). If you go down this path, pay attention to bit 4 of the hSerSetup mode parameter.
I ran into similar timing conflicts & blocking today using a 14M2. I was using servo commands along with SERIN from a Bluetooth module and SEROUT to an MP3 player. Hserin and Hserout saved the day, everything is playing together nicely now. Nice to have these hardware workarounds. Too bad the 14M2's SEROUT pin is also the only Hserout pin though, it wreaks havoc on sertxd info sent to the serial terminal.
 

PhilHornby

Senior Member
Too bad the 14M2's SEROUT pin is also the only Hserout pin though, it wreaks havoc on sertxd info sent to the serial terminal.
You can move HSEROUT from B.0 -> C.1 (but you lose hwpm B, which may matter to you) ...
Rich (BB code):
#picaxe 14M2
;
; SFRs
;
; To convert to Picaxe equivalent, we do the following:-
;
; For example, OSCCON = 0x99 in datasheet
;
;  0    9    9
;0000 1001 1001
; |   |xx|   /       xx = discarded
;  \  / /   /
; 0011 1001/
;   3    9
;
Symbol APFCON0 = $5D                      ;$11D - Alternate Pin Function Control (0)

      PeekSfr APFCON0,b0                  ;Get current contents of APFCON0
      b0 = b0 AND %11111011               ;clear bit 2 (TXCKSEL)
      PokeSfr APFCON0,b0                  ;Hserout now on RC4 (C.1 in picaxe terms)
     
      hsersetup B9600_4,%00
      hserout 0,(cr,lf,"Hello World!")
(Untested - modified from working 08M2 version - might need pokesfr after hsersetup)

14m2datasheetpartof.png 14m2pinouts.png

(See what I learned, by reading Allycat's posts :D)
 
Last edited:

AllyCat

Senior Member
Hi,

Too bad the 14M2's SEROUT pin is also the only Hserout pin though, it wreaks havoc on sertxd info sent to the serial terminal.
Are you sure about that? From the PIC16F1825 data sheet (page 121) it looks as if APFCON0.TXCKSEL can swap it (back) onto RC4 (Leg6 = PICaxe pinC.1).

I believe that requires bit2 of SFR $5D (bank2, address $1D) to be cleared. So try PEEKSFR $5D,b0 : b0 = b0 ^ 4 : POKESFR $5D,b0.

Ah, Phil beat me to it !

Cheers, Alan.
 

hippy

Technical Support
Staff member
Code:
PeekSfr APFCON0,b0
b0 = b0 AND %11111011
PokeSfr APFCON0,b0
      
hsersetup B9600_4,%00
hserout 0,(cr,lf,"Hello World!")
I haven't tried it but guess it works and it's technically okay to do it that way.

Generally, and particularly when investigating what can be done, it is best to twiddle the SFR registers after any PICAXE initialisation commands - that is HSERSETUP then PEEKSFR/POKESFR, this will ensure that the in-built commands don't clear something one has tried to set-up.

To clear bit 2 as here, my preference would have been ...

Code:
PeekSfr APFCON0, b0
bit2 = 0
PokeSfr APFCON0, b0
 
Top