• AVR Freaks

Hot!PWMEN Not Working As Expected

Author
RogerAF
Super Member
  • Total Posts : 295
  • Reward points : 0
  • Joined: 2007/06/30 20:48:04
  • Location: Orlando, Florida
  • Status: offline
2020/09/20 15:48:44 (permalink)
0

PWMEN Not Working As Expected

I'm using a PIC12F1571. I have two versions of my program: 6 and 6a. In version 6 I start all three PWM modules using the following:
   movlb .27 ; Load Bank Select Register: Bank-27
   movlw b'11000000' ; PWM-1 Module & Output Enable
   movwf PWM1CON ; PWM-1 Enable Module
   movwf PWM2CON ; PWM-2 Enable Module
   movwf PWM3CON ; PWM-3 Enable Module
In version 6a I'm trying to use this:
   movlb .27 ; Load Bank Select Register: Bank-27
   movlw b'00000111' ; PWM Modules 1, 2, & 3 Output Enable
   movwf PWMEN ; PWM Enable Modules 1, 2, & 3
This is the only difference between the versions working and not working. I tried changing the Bank to 31, but that didn't help. The data sheet says the following:
Each PWM module can be enabled individually using
the EN bit of the PWMxCON register, or several PWM
modules can be enabled simultaneously using the
mirror bits of the PWMEN register.
and the register definition looks like this:
REGISTER 22-17: PWMEN: PWMEN BIT ACCESS REGISTER
U-0 U-0 U-0 U-0 U-0 R/W-0/0 R/W-0/0 R/W-0/0
— — — — — PWM3EN_A PWM2EN_A PWM1EN_A
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit
u = Bit is unchanged x = Bit is unknown U = Unimplemented bit, read as ‘0’
‘1’ = Bit is set ‘0’ = Bit is cleared -n/n = Value at POR and BOR/Value at all other Resets
bit 7-3 Unimplemented: Read as ‘0’
bit 2-0 PWMxEN_A: PWM3/PWM2/PWM1 Enable bits
Mirror copy of EN bit (PWMxCON).

OK so copies from PDF files don't translate, but you get the idea. If not, it is at the top of page 227 in the PIC12(L)F1571/2 data sheet. (Tried uploading the data sheet, but I guess it's too big. Sorry about that chief.)
Both versions are attached.
Thank you in advance.
Aloha
#1

7 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28675
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PWMEN Not Working As Expected 2020/09/20 16:23:43 (permalink)
    +2 (2)
    RogerAF
    ...
    I tried changing the Bank to 31, but that didn't help.

    Well it should have.
    Bank 27 is definitely wrong for that register.
    Why not use BANKSEL instead so you don't have to check?
    i.e. change
        movlb .27 ; Load Bank Select Register: Bank-27
    to
        BANKSEL PWMEN    ; select correct bank to access PWMEN
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    RogerAF
    Super Member
    • Total Posts : 295
    • Reward points : 0
    • Joined: 2007/06/30 20:48:04
    • Location: Orlando, Florida
    • Status: offline
    Re: PWMEN Not Working As Expected 2020/09/21 10:54:00 (permalink)
    0
    Thanks Ric,
    I agree, it SHOULD have. So I tried your suggestion, but still, there is no joy in Mudville. Could this be a bug?
    #3
    mbrowning
    USNA79
    • Total Posts : 1811
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: PWMEN Not Working As Expected 2020/09/21 13:27:30 (permalink)
    +2 (2)
    It's definitely a bug.
    In 6 you are setting the OE bits (PWMxCON = 0b11000000).
    In 6a you are leaving the OE bits cleared (never touch PWMxCON).
    Maybe things would work better if you enable the outputs prior to loading the PWMEN register.
    #4
    RogerAF
    Super Member
    • Total Posts : 295
    • Reward points : 0
    • Joined: 2007/06/30 20:48:04
    • Location: Orlando, Florida
    • Status: offline
    Re: PWMEN Not Working As Expected 2020/09/22 14:56:58 (permalink)
    0
    Thanks mbrowning,
    That seems to be the solution. In Version 6b I shifted the Power Up Delay section to before the PWM Initialization. Then tried your idea like so:
    ;***** Start Pulse Width Modulators
       movlb .27 ; Load Bank Select Register: Bank-27
       movlw b'01000000' ; PWMx Enable Outputs
       movwf PWM1CON ; PWM-1 Enable Output
       movwf PWM2CON ; PWM-2 Enable Output
       movwf PWM3CON ; PWM-3 Enable Output
    ; movlb .27 ; Load Bank Select Register: Bank-27
    ; BANKSEL PWMEN ; select correct bank to access PWMEN
       movlw b'00000111' ; PWM Modules 1, 2, & 3 Enable
       movwf PWMEN ; PWM Enable Modules 1, 2, & 3
    ;
    As you can see, Bank 27 serves all. I think this means the outputs could be enabled as part of the initialization, then the PWM modules can be triggered at a later time.
     
    About BANKSEL vs MOVLB: to me BANKSEL is focused on a single register, whereas MOVLB loads the BSR with an address that serves all registers in the bank.Perhaps the code is less readable, but having a bunch of BANKSELs for each register used just seems redundant. I figure the Assembler is just turning BANKSEL into MOVLB anyway.
    #5
    ric
    Super Member
    • Total Posts : 28675
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PWMEN Not Working As Expected 2020/09/22 14:59:30 (permalink)
    +1 (1)
    Yes, the assembler is turning BANKSEL into MOVLB, but it's much less error prone.
    You don't have to do it for every register access, but you do need to keep track of which registers are in the same bank if you don't.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    RogerAF
    Super Member
    • Total Posts : 295
    • Reward points : 0
    • Joined: 2007/06/30 20:48:04
    • Location: Orlando, Florida
    • Status: offline
    Re: PWMEN Not Working As Expected 2020/09/22 15:01:27 (permalink)
    0
    P. S. I was going to upload the last version, but when I tried using the Full Version Reply, I got an Access Denied Error. I tried again, same thing. I gave it 1/2 an hour, no joy. So I worked on other stuff all day and tried just now. I STILL got the same error. So you'll have to make do without the whole program.
     
    If anyone can tell me how to avoid this error, please do.
    #7
    ric
    Super Member
    • Total Posts : 28675
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PWMEN Not Working As Expected 2020/09/22 15:56:01 (permalink)
    0
    It's probably something triggering the stupid firewall.
    You can usually avoid that by attaching the file rather than pasting it inline.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5