# Overwriting PWM Pin?

Status
Not open for further replies.

#### Suraj143

##### Active Member
I'm generating a frequency using PWM module (RB3).

My question is when I write data to the whole port (PORTB) will that PWM pin get affected?

ex:
Code:
	movlw 	b'10111110'
movwf	PORTB
Thanks

#### smanches

##### New Member
I don't think it will do anything. Once you map a pin to one of the peripherals, any writing to the pin is usually disabled. You need to use the peripheral modules registers to modify the settings.

#### Pommie

##### Well-Known Member
If PWM is enabled then writing to the port has no effect.

Mike.

#### Suraj143

##### Active Member
Totally understood, a clear reply thats what I want to know.

Thanks guys

#### Leftyretro

##### New Member
I would research this a little farther if I was you.

A recent bug in the Arduino PWM libary code was found such that if the PWM duty cycle was set to 0% there would still be a very small positive pulse output, in other words the duty cycle could be changed only from 1% to 100%, but not 1% to 0%. This was fixed in the next upgrade to the libary code but the temporary fix was to just test the duty cycle value and if less the 1 then write a 0 to the outout pin. So in that case a digital output instruction was overiding the normal PWM output.

Not saying that this applies to your processor chip or your software routines that support the PWM module, but the real answer should be in the the data sheet for your processor chip. Or you could write a simple program to see if doing a direct output instruction would overide or effect a ongoing PWM routine.

Lefty.

#### Pommie

##### Well-Known Member
In this case I assumed that we were talking about a Pic and in the case of RB3 the diagram is clear on the way the module overrides the I/O function.

Edit, your point with regard to possible hardware and software bugs is valid but I don't believe it to be a problem in this case.

Mike.

#### Attachments

• 28 KB Views: 73
Last edited:

#### Leftyretro

##### New Member
In this case I assumed that we were talking about a Pic and in the case of RB3 the diagram is clear on the way the module overrides the I/O function.

Edit, your point with regard to possible hardware and software bugs is valid but I don't believe it to be a problem in this case.

Mike.
Yes, I made no assumtions about the device, just brought up the possiblity. I come from a hardware backround so when I come across something like this and don't want to or can't understand the software/hardware relationship or the data sheet's explantation, I just try and see if I can write a simple testing program to see if I can break the function or not, but that's just me. I tend to trust what I can see on a scope. LOL

Lefty

Last edited: