settimer & hpwm conflict 28X1

retepsnikrep

Senior Member
I'm using the settimer t1s_8 command to generate 1 second ticks in 'timer' at 8mhz, which I count and use as the basis for a one minute timer.
No problem. ;)

Now I have introduced a Hpwm command to my software

hpwm 0,0,%1100,255,0

Which starts the internal HPWM outputs 1 & 4 at 0% duty cycle.

However the hpwm output is being corrupted by the settimer/ticks or something timer related as the program loops. The output is wildy erratic.

If I REM out the 'settimer' command HPWM works fine straight away.

Is this a known issue, any workrounds. I can't use simpler pwmout as those pins are in use on my 28X1.

Thanks
 

tiscando

Senior Member
There's nothing in the manual at the HPWM command saying that it gets corrupted by the settimer command. Is the timer's timing affected by the HPWM too?
 

Technical

Technical Support
Staff member
Yes this is a known conflict with the internal timer interrupts within the PICmicro, which another user pointed out to us. After a lot of research we discovered an internal PIC timer flag is becoming set where we did not expect it.

Now we know what is happening we have actually worked around the issue in the current firmware version (A.4) so that timer and hpwm/pwmout can be used together. We guess you have version A.3, unfortunately no workaround on that part.
 

retepsnikrep

Senior Member
Technical thanks for that advice. I fully appreciate the hard work and effort that's gone into the Picaxe and the excellent support users recieve on this forum. I'm sorry there is no workaround for the A3 version :(

I was expecting the commands to work, and this is a firmware issue preventing my software working as expected, can I return my two 28X1 A3 pics to tech supplies UK for free re-programming/swapping to the A4 version? ;)

I do need those functions, and it would be aditional expense for me to have to buy some new ones to fix a problem that's not by fault :(

I'm happy to pay the postage :)
 
Last edited:

tiscando

Senior Member
I also have a problem between settimer and hi2c. I am trying to use the hi2c as a digital oscilloscope. It worked well, but if I added the 'settimer' command after the hspisetup, the picaxe-28x1 version a.3 (as suggested by the firmware button) gets stuck on this line, and then restarts after 2 seconds as if it did a 'reset' command. Meanwhile, is all of this code correct? (it passed the complier)
edit: I used the very long line of '@ptrinc's for maximum and reliable speed. Could there be a scrollbar on the left side of the codebox as well as on the right? I had to scroll a long way horizontally to click the 'edit' and 'save' button, and even fully read this message.
edit2: I can always hard-reset the picaxe quickly to download a new program into the 28x1.

Code:
setfreq m8 'the usual!
disconnect
gosub readbuf
high portc 6
settimer 65531 'this is the line where the program gets stuck.
sertxd ("start!",13,10)

main:
ptr=0
do
'if pin0=1 then gosub readbuf
loop until pin4=b21
timer=0
hspiin (@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc)
w2=timer
for ptr=0 to 126
b0=@ptr
w1=ptr*8
sertxd (#w1,":",#bit7,#bit6,#bit5,#bit4,#bit3,#bit2,#bit1,#bit0,13,10)
if porta pin1=1 then main
if pin0=1 then gosub readbuf
next ptr

w4=w2/25*4
b7=w2//25
select b7
case >6
	w4=w4+1
	b7=b7*4-25*4
case >12
	w4=w4+2
	b7=b7*4-50*4
case >18
	w4=w4+3
	b7=b7*4-75*4
else
	b7=b7*16
endselect
sertxd ("time taken: ",w4,".",b7,"ms",13,10)
toflag=0
goto main

Readata:
read 0,word w11
read 2,b21
return

sendata:
sertxd ("read baud rate: ",#b21,": ",#w11,13,10)
return

readbuf:
high portc 7
readoutputs b26
let pins=0
sertxd ("define baud rate: ")
serrxd b27,b23,b24,b25
w11=b23-48*100'b22:b23
b24=b24-48*10
b25=b25-48
w11=w11+b24+b25

select b27
case "r","R"
	gosub readata
	gosub sendata
	sertxd ("cont ")
	goto readbuf
case "z","Z"
	sertxd ("reconnect - ")
	gosub readata
	gosub sendata
	sertxd ("end program.",13,10)
	setfreq m4
	reconnect
	let pins=0
	low portc 4,5,6,7
	end

case "n","N"
	write 2,1
	write 0,w11
	sertxd ("recieve N",#w11,", return",13,10)
case "t","T"
	write 2,0
	write 0,w11
	sertxd ("recieve T",#w11,", return",13,10)
else
	sertxd ("invalid entry.",13,10,"cont ")
	goto readbuf
endselect
gosub readata
low portc 7
hspisetup spimode01, w11
return
 
Last edited:
Top