picaxe 28x2 and 4 pwmout, pwmout command issue?

pippofjk

Member
Hello!

I'm using a picaxe 28x2 with B.3 firmware and the 5.5.1 compiler version for windows.

I'm using 4 pwmout commands to control the speed of 4 motors. Each channel is connected to an l293d driver. Every channel of pwm have the same period and different duty cycles. After have initialized the pwmout i use the pwmduty command for changing the duty.

this is the code:

Code:
begin:
           pause 100

           high B.7 , B.4   'move forward
	low B.6 , B.3

	pwmout pwmdiv4, B.5, 99, 200
	pwmout pwmdiv4, B.0, 99, 200
	pwmout pwmdiv4, C.1, 99, 200
	pwmout pwmdiv4, C.2, 99, 200

main:


	pwmduty B.5, 250
	pwmduty B.0, 250
	pwmduty C.1, 250
	pwmduty C.2, 250

           pause 4000

	pwmduty B.5, 100
	pwmduty B.0, 100
	pwmduty C.1, 100
	pwmduty C.2, 100

           pause 4000

goto main
The strange thing is that only the last channel of pwm that starts present the strange behavior.
I haven't an oscilloscope but, when i measure the voltage of each port motor of the l293d, the last one that started have a different voltage from the others (approximately 2,5 volt), so, in this case, C.1 and C.2 that share the same timer have this issue.

But if change the order of stat up, for example, B.0 now is the last:

Code:
begin:
           pause 100

           high B.7 , B.4      'move forward
	low B.6 , B.3

	pwmout pwmdiv4, C.1, 99, 200
	pwmout pwmdiv4, C.2, 99, 200
	pwmout pwmdiv4, B.5, 99, 200
	pwmout pwmdiv4, B.0, 99, 200

main:



	pwmduty C.1, 250
	pwmduty C.2, 250
	pwmduty B.5, 250
	pwmduty B.0, 250

           pause 4000


	pwmduty C.1, 100
	pwmduty C.2, 100
	pwmduty B.5, 100
	pwmduty B.0, 100

           pause 4000

goto main
So now, only B.0 have the issue described above: the last that i started

If B.5 would be the last, only B.5 would have the problems.

I suggest that could be a problem of my program or a problem of the compiler, because always the last pwm that starts, has this issue.
How can i use all the 4 pwm channel together?

Thanks.
 

hippy

Technical Support
Staff member
I have added a document which describes the issues of using PWMDIV options with multiple PWMOUT commands for the 28X2 and 40X2 here ...

http://www.picaxeforum.co.uk/showthread.php?21867-Using-PWMDIV-options-with-the-PICAXE-28X2-and-40X2&p=212760#post212760

Basically, the lastest PWMDIV causes earlier PWMDIV settings to be reset ( to divide by 1 ), and they need to be manually forced if using multiple PWMOUT and using PWMDIV. This only applies to the 28X2 and 40X2.

In this case, it seems that the problem is perceived in only the last PWMOUT pin being set as having a problem. The reality is that only the last PWMOUT set may be giving what the programmer expects, so there may be other issues at play here.
 

pippofjk

Member
Now works well with the following code:

Code:
' @ freq: 8 Mhz, with pwm frequency: 5000 Hz.

	pwmout pwmdiv4, B.5, 99, 200
	pwmout pwmdiv4, B.0, 99, 200
 	
 	pwmout pwmdiv4, C.1, 99, 200
	pwmout pwmdiv4, C.2, 99, 200
 		
 'force B.5 to pwmdiv4
 
 	peeksfr $51, b0
 	bit0 = 1
 	bit1 = 0
 	pokesfr $51, b0
 	
 'force B.0 to pwmdiv4
	
	peeksfr $4A, b0
 	bit0 = 1
 	bit1 = 0
 	pokesfr $4A, b0
Thanks hippy!
 
Top