I must really be missing it....

Cunci

New Member
I am using a 28x1 Version A.5. I setup the hardware serial port. I start a pwm on pin 12. In the example below the pwm works fine until the hardware serial port receives one character then the pwm stops.


#picaxe 28x1
setfreq em16 'SerTxd is 19200 @ 16Mhz

hsersetup B19200_16, %01 'true serial output, automatic background receive
pwmout 1, 199, 104 'initialize PWM

do : loop
end
 

jglenn

Senior Member
If pwm is like servo out, in terms of using overhead, they can't both work at the same time. See this ref:

blimpyway
01-05-2005, 18:10
Hi,

I understood from manual that during serin serout the servo pulses (working in background) are interrupted.
My question is - is this a serious issue?
As an example - is possible to make a reliable serial servo controller with a picaxe continously (or at least 10-20 times every second) receiving servo position updates over serial line and issuing servo command to modify servo position accordingly.

Thanks
hippy
01-05-2005, 23:58
From my understanding of it, while executing a SERIN and waiting for a data byte to turn up the SERVO will not be updated. That becomes a more serious issue the longer you have to wait for a character. If you are only sending one character every 20 seconds you will probably encounter problems.
 

Cunci

New Member
I just tested to see if 16Mhz had someting to to with this problem. It does not. My opinion is that the hardware serial ISR has a serious problem.
 

jglenn

Senior Member
It sounds like the serial routine is not returning to the main program. Does the PIC have a hardware UART, or is it all software? I would think there should be a short delay when the char comes in, and then it goes back to running.
 

hippy

Ex-Staff (retired)
HSERSETUP in the current case utilises the hardware UART and uses the background receive mode of the 28X1 Firmware. As I understand it, interactions there may be of SERIN with SERVO should not have any adverse effect with this configuration.

There have been unwanted interactions previously identified in a number of cases which have related to PWMOUT because of unexpected behaviour of the chip itself and this may be another case not previously identified though I am unsure how such an interaction arises at this time if that is the case.

I have not been able to replicate the same configuration nor failure with the hardware I have to hand but we will investigate this further.
 
Last edited:

BCJKiwi

Senior Member
Thought this had been resolved;

06-01-2009, 00:10 #5 Technical
Technical Support

Join Date: Jan 1970
Location: Bath,UK
Posts: 3,463



The hardware pwm module inside the PIC chip used for the 28X1/40X1 creates a 'timer 2' interrupt by setting the timer 2 interrupt flag when the PWM module is active. This is unusual behaviour because, although timer 2 is used by pwm, it is not used in interrupt mode, hence the interrupt flag should not be generated. This also doesn't occur in other PICs we have used in the past.

Unfortunately this silicon issue can effect other commands that legitimately use interrupts - namely servo, timer, hardware i2c (slave mode) and hardware serial.

When we became aware of this limitation of the internal PICs hardware we changed the PICAXE bootstrap to 'workaround' this issue (A.4 onwards). So A.4 onwards chips should work for you.
__________________
PICAXE Technical Support
But maybe you need to use Hpwm not pwmout?

The H on serial and pwm indicates that additional hardware functionality within the chip is being used which provides for background operation.

Please try that and and advise if the problem still exists - am waiting for post A.2 28X1s to arrive so cannot test right now.
 

hippy

Ex-Staff (retired)
HPWM and PWMOUT both use the background generating PWM hardware. HPWM allows access to the additional Enhanced PWM abilities of the chip. I would not expect HPWM and PWMOUT to behave differently in terms of internal interactions but cannot say that definitively.

It could be worthwhile trying it but it will depend on what those interactions are, if any, something we will investigate.
 

Technical

Technical Support
Staff member
A quick test on A.5 and our system worked ok.
One question, are you sure your serial signals are correct - because, if the serial byte is not completely received correctly, after 2 seconds or so the chip will reset. Try putting a flash of an LED or similar at the start of your program to see if this is happening.
 

Cunci

New Member
Thanks Hippy and Technical. I have results of further studies. There is problem in the hardware serial port interrupt service routine in the 28X1 V A.5.

I used the following code to test:
#picaxe 28x1

hsersetup B19200_4, %01 'true serial output, automatic background receive
pwmout 1,199, 200 'initialize PWM, 10K 25% (Channel 1 on scope)
gosub ResetSerialPort

do
high portc 3 : low portc 3 '(Channel 2 on scope)
if hserinflag = 1 then
b5 = @ptr
disconnect : sertxd ("char: ", b5) : reconnect
gosub ResetSerialPort
endif
loop

ResetSerialPort:
hserinflag = 0 'reset new background data recieved flag
hserptr = 0 'reset data write pointer
ptr = 0 'reset data read pointer
return

end

1. I start the program and everything runs fine; PWM 1 works and portc 3 toggles.
2. Using Hyperterminal send a character to the PICAXE. Immediately the PWM stops. portc 3 continues to toggle.
3. Just to eliminate the possibility of a serial framing error, I retransmit the character to the PICAXE debugging terminal and it is exactly the character that I transmitted from Hyperterminal.

Something in the serial ISR is stopping the PWM. I have bmp's of my scope if you would like to see them.

Thank you again.
 

Technical

Technical Support
Staff member
How is your hardware setup - are you using a MAX232 device between the computer and the PICAXE hardware serial input?
 
Top