Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic micro RMW issues again.

Status
Not open for further replies.

dr pepper

Well-Known Member
Most Helpful Member
I've been caught out with this one a few times, but no like this.
I have software that generates pwm, not using the ccp, in software, there are 2 channels using portb,0 and portb,1.
The pwm routines runs in a loop continuously, while everything else runs in an inetrrupt.
The pwm works fie, however if I try and use any other bits on portb as outputs the output appears for a fe uS, but as soon as the inetrrupt retrurns to the pwm routine the output clears itself.
Seems like a rmw issue, however it still does it with nothing but a 'scope or logic analyser connected to the pic.
Whats going on here then, is it due to the freq that the pwm o/p's are operating, about 500hz?
 
Are you sure the port isn't set as analogue? Analogue pins always read back as zero.

Mike.
 
It sound to me like you are updating the whole port in the PWM routine instead of the required bit(s). If you are writing to the TRIS registers, then it shouldn't be a RMW error.

Without code we can but speculate...
 
Ansel is cleared, trisb is cleared, atod disabled, Im using the uart but thats a different port on this chip.
Heres the code for the pwm.
One thing I just realised \i'm not saving w or status reg on an inerrupt, might rectify that next.
There are 2 lots of this that run in a loop:

Code:
;
;---------------------------pwm section-----------------------------------
;
pwmo    movf    pulsehi,w            ;o/p high for pwm cycles
        btfsc    status,z
        goto    lows
;
        movlw    b'00000001'
        iorwf    portb,f
        decf    pulsehi,f
        retlw    d'0'
;
lows    movf    pulselo,w            ;output low for pwm-128 cycles
        btfsc    status,z
        goto    reload
;
        movlw    b'11111110'
        andwf    portb,f
        decf    pulselo,f
        retlw    d'0'
;
reload    movf    pwm,w
        movwf    pulsehi                ;tranfer desired pwm to pulsehi
        movlw    d'128'
        movwf    pulselo
        movf    pwm,w
        subwf    pulselo,f            ;and put the opposite in pulselo
        retlw    d'0'
 
I think I might have mentioned the '886 on other posts, its a chip I've grown to like, this is a completly different project.
I get the issue with absolutely nothing connected to the chip, except a 'scope and I also tried it with my salae.
I understand that if I hit the current limit and cuase the pin not to be able to change state by the time its next read I'll get the rmw issue, but with a 10m ohm 10pf load i wouldnt have thought so, something else is happening.
I have found a seperate issue on port a, I dont think I've disabled the comparator or something as bits 0 and 1 as inputs dont change state as inputs.
As far as I can tell this chip powers up without having to mess with the comparator unlike the 18 pin pics.
Maybe I blew this chip, I'll try another.
 
What chip are you using?

Edit, not saving context in the ISR would definitely cause problems like this. That is the first thing I would fix.

Mike.
 
Pic16f886 as mentioned further up.

Yes I will mod the code to context save, using and and ior functions i can see this messing up easily, however it still messed up using bcf and bsf, but I'll not speculate anymore till th ecodes modded.

I still havent worked out why porta 0 and 1 are not working as inputs.

Edit: Sussed porta 0 and 1 as i/p's, ansel on this chip is in memory page 3, my code assumes page1, ah well.
 
Last edited:
I think I might have mentioned the '886 on other posts, its a chip I've grown to like, this is a completly different project.
You may think this says you're using the 886 but it doesn't. Hence why I asked the question.

So it was an analogue problem all along. Did you also clr anselh?

Mike.
 
Could this be solved using the simulator? Not using the 16F family anymore. More than 5 years now, I think.
 
I dont know, doesnt the sim not take i/o into account, or do you mean icd.
The 16f series is still very popular as far as I know, or are you saying you have moved to another series, the 18f series are now a lot cheaper, I used the 18f26k20 a while back.
 
I dont know, doesnt the sim not take i/o into account, or do you mean icd.
The 16f series is still very popular as far as I know, or are you saying you have moved to another series, the 18f series are now a lot cheaper, I used the 18f26k20 a while back.
Yes I moved to the 18F family since then. That I recall, used 18F 4431, 452, 4585, 4550, 4520 and some more.

In fact I had in mind the simulation just for the domestic chores. To actually check what "should" be output with the idea to discard an error in the soft.

Somebody mentioned something like setting/resetting bits in the TRIS registers. I used that for my (now canned & unchanged) keyboard reading routine.
 
I might be able to do that with the pickit3, i/o troubles have not been much od an issue for me before.
 
Proteus ISIS sim of the 16F886 which I use a lot does show RMW issues. I simply buffer the ports with a GPR.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top