poke sfr, pwm alternate pin??

tony_g

Senior Member
im using an 08m2 to control an H bridge chip for my scale winch controller and was curious if i could use the poke sfr to switch the output pin for the pwm signal, im sure a long while ago i read this question asked by someone else but cant find what im looking for.

currently i have c.0 and c.1 controlling the P channels of the h bridge and c.2 and c.4 for the two N channels, the pairs for forward and reverse being c.0 (p-ch) + c.2 (n-ch) for forward and c.1 (p-ch) and c.4 (n-ch) for reverse.


after looking at the datasheet for the 12F1840 and the APFcon it seems that the pwm feature can be redirected to several different pins.

what im curious to know from the more experienced is can i by means of the poke sfr command get the pwm output to work so i can pwm one of the pins for the reverse function pins (c.1 or c.4) as i can already use it for forward via c.2 as the default pin


thanks,

tony
 

Technical

Technical Support
Staff member
No, PWMout (CCP1 in the Microchip datasheet) cannot be redirected to either of those 2 pins.
 

Goeytex

Senior Member
CPP1 can only be alternately steered to Leg 2 (C.5). However this is also the serin pin. So you would have to use "disconnect" before redirection. N0t even sure that it will work.
 

tony_g

Senior Member
darn it, oh well i was hoping their was a chance when reading through the datasheet

24.4.5 PWM STEERING MODE
In Single Output mode, PWM steering allows any of the
PWM pins to be the modulated signal. Additionally, the
same PWM signal can be simultaneously available on
multiple pins.

Once the Single Output mode is selected
(CCP1M<3:2> = 11 and P1M<1:0> = 00 of the
CCP1CON register), the user firmware can bring out
the same PWM signal to one or two output pins by
setting the appropriate STR1 bits of the PSTR1CON
register, as shown in Table 24-8.

but im sure i saw a post in the past where someone was able to get the pwm redirected to a different pin on the 08m2 ( not c.5 ) i shall have to search some more.

thanks,

tony
 

tony_g

Senior Member
well i finally got round to playing with the special function registers and for now have pinC.0 giving the pwm signal, by changing either bit 0 or bit 1 of the pwm steering register via the poke sfr command i can now have 2 pwm outputs with a little easier coding than the previous example i posted earlier.

next up to play with the APFcon register to see if i can move it over to PINC.4 which is the alternate pin location for the pwm P1B output which is currently on PINC.0.

rough code attached if anyone else wants to play with it, for now its just ramping up/down an led on c.2 then changing the pwm steering to c.o doing the same and looping back round.



Code:
#picaxe 08m2
#no_data
#com 6


symbol pwm0 = %00000001    ;sfr pwm steering register,pwm on c.2
symbol pwm2 = %00000010    ;sfr pwm steering register,pwm on c.0

;****** $b6 pwmsteering bank & address ******

main:

do
for w0 = 0 to 399
	pwmout 2,99,w0
	pause 1
next w0

for w0 = 399 to 0 step-1
	pwmout 2,99,w0
	pause 1
next w0

pwmout 2,off
pokesfr $b6,pwm2

for w0 = 0 to 399
	pwmout 2,99,w0
	pause 1
next w0
	
for w0 = 399 to 0 step-1
      pwmout 2,99,w0
      pause 1
next w0

pwmout 2,off
pokesfr $b6,pwm0

pause 500
loop
 

Rick100

Senior Member
Hello tony_g,
Nice work on using the steering control register to switch the pwm ouput from C.2 to C.0. I tried your code and it works great. I added a pokesfr to the APFCON register and got the pwm output on C.4(leg3). It didn't work at first, but it was because I hadn't set c.4 as an output.

Here's the code I used.

Code:
'steer pwm to different pins using apfcon and pstr1con registers
'started with code from tony_g on Picaxe forum
'green led on c.2
'red led on c.0
'yellow led on c.4


#picaxe 08m2
#no_data


symbol pwm2 = %00000001    ;sfr pwm steering register,pwm on c.2
symbol pwm0 = %00000010    ;sfr pwm steering register,pwm on c.0

symbol PSTR1CON = $b6
symbol APFCON = $5d


main:

output c.4	'required to put pwm on the pin

pause 1000
sertxd("Reset",13,10)


do

	gosub green
	gosub cycleLed
	pause 1000
	
	pwmout 2,off
	
	gosub red
	gosub cycleLed
	pause 1000

	pwmout 2,off
	
	gosub yellow
	gosub cycleLed
	
	pause 500
	
	'test for pwm on c.4 and sertxd on c.0
	pwmduty 2,30	'dim led
	sertxd(13,10,13,10,"testing 1 2 3",13,10)
	
	pause 3000
	
	pwmout 2,off

loop

green:
	'use P1A(normally on c.2) for pwm output
	pokesfr PSTR1CON,pwm2

return

red:
	'P1B(normally on c.0) on c.0
	peeksfr APFCON,b0
	bit1 = 0
	pokesfr APFCON,b0
	'use P1B for pwm output
	pokesfr PSTR1CON,pwm0

return


yellow:
	'P1B(nprmally on c.0) on c.4
	peeksfr APFCON,b0
	bit1 = 1
	pokesfr APFCON,b0
	'use P1B for pwm output
	pokesfr PSTR1CON,pwm0

return

cycleLed:
	for w0 = 0 to 399
		pwmout 2,99,w0
		pause 1
	next w0
	
	for w0 = 399 to 0 step-1
		pwmout 2,99,w0
		pause 1
	next w0
return
 

tony_g

Senior Member
hi rick, thanks for the contribution for c.4.

i was just going over the pic datasheet and about to play with the apfcon and changing the p1b output to the alternate pin and had just gone through the same issue of getting no output but you have beat me to it lol

nice work and thanks for adding that pin.


tony
 
Top