Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop working.


Today 16:11
Forum: Absolute Beginners Section
Starter: moonshadow
Views: 0
Replies: 42
Today 12:57
Forum: Proton Studio
Starter: Puffeltje
Views: 0
Replies: 3
Today 10:13
Forum: Proton Studio
Starter: wirecut
Views: 0
Replies: 0
Today 09:37
Forum: Proton Studio
Starter: Puffeltje
Views: 0
Replies: 0
Today 09:25
Forum: Proton Studio
Starter: Puffeltje
Views: 0
Replies: 0
Yesterday 19:56
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 32
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Junior Member SebaG's Avatar
    Join Date
    Sep 2013
    Posts
    27
    Thumbs Up
    Received: 4
    Given: 3
    Total Downloaded
    977.98 MB

    0 Not allowed!

    Default Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop working.

    For several days I was struggling with the code below and I'm honestly fed up with it - do you see something that I do not see? 2.5V power supply from batteries, fully functional batteries, PIC has been replaced with a new one and still nothing.


    In the program I read the ADC value from the potentiometer slider (ADC_Raw), which I then give as PWM value (Duty).


    For the values given in the code, everything works well, a beautiful PWM is generated with f = 15.6kHz. However, I need PWM with a lower frequency and I wanted to use a TMR2 module prescaler, but any other setting than 1:1 as in the working code below (T2CON = 0x4) causes that the system stops! It does not work, does not generate PWM. I really do not have a concept anymore. What's worse, I can not change the hardware because I'm already soldering on the fabricated PCBs. Do you have any ideas what could be wrong?

    Code:
    Device = 10F322
    
    
    Config FOSC_INTOSC, BOREN_OFF, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, LVP_OFF, LPBOR_OFF, BORV_LO, WRT_OFF
    Declare Xtal 4
    OSCCON = 0x50                                                                                                      
    Declare All_Digital On                                                                        
    
    TRISA = 0x4
    PORTA = 0x0
    
    
    Dim Duty As Word
    Dim ADC_Raw As Byte
    
    
    Main:
        GoSub AD_Conv
        GoSub PWM_1 
    GoTo Main
    
    
    '==============================================================================================
    AD_Conv:                                                                                
    '==============================================================================================
        ANSELA = 0x4                                                                    
        ADCON = 0x28                                                                     
        
        ADCONbits_ADON = 1                                                                   
        ADCONbits_GO_DONE = 1                                                              
            While ADCONbits_GO_DONE = 1                                                    
            Wend                                                                             
        ADC_Raw = ADRES                                                                 
        
        ADCONbits_ADON = 0                                                                   
        ANSELA = 0x0                                                                  
    Return
    '==============================================================================================
    PWM_1:                                                                                
    '==============================================================================================
        Duty = ADC_Raw
        PWM1DCL.6 = Duty.0
        PWM1DCL.7 = Duty.1
        PWM1DCH = Duty >> 2
        PR2 = 0x3F
        TMR2 = 0x0
        T2CON = 0x4
        PWM1CON = 0xC0
    Return
    Last edited by SebaG; 29th June 2018 at 19:46.

  2. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Junior Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    67
    Thumbs Up
    Received: 11
    Given: 9
    Total Downloaded
    2.04 GB

    0 Not allowed!

    Default Re: Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop worki

    Did you resolve this?
    Flosi Guđmundsson
    Reykjavík

  4. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    466
    Thumbs Up
    Received: 38
    Given: 7
    Total Downloaded
    2.88 GB

    0 Not allowed!

    Default Re: Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop worki

    I think the problem may be with the PWM1 code.
    If I understand the original post correctly the period is fixed and a variable duty set by the ADC value is required, in that case should not...
    Code:
    PR2 = 0x3F
    TMR2 = 0x0
    T2CON = 0x4
    PWM1CON = 0xC0
    be placed before main as...
    a) You only need to configure them once and
    b) By having TMR2 = 0x0 in the PWM1 subroutine the value in TMR2 is being cleared every time the subroutine is called, so how can it ever be clocked high enough to reach the period comparison value in PR2?

    I may be wrong but I suspect it only worked at higher frequencies by pure chance because the ADin command hogs the processor constantly polling the the Go/Done bit until the conversion ends and that the conversion time just happened to be long enough at that frequency for the TMR2 count to reach the PR2 period comparison value before it was cleared in the PWM1 subroutine.

  6. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    49
    Thumbs Up
    Received: 14
    Given: 0
    Total Downloaded
    144.28 MB

    0 Not allowed!

    Default Re: Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop worki

    I have to ask, Why are you manipulating the ANSELA each time you enter the AD_Conv routine? This can be set once before the main loop. Also why are you turning off the A/D converter module each time you exit the AD_Conv routine?

  8. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Junior Member SebaG's Avatar
    Join Date
    Sep 2013
    Posts
    27
    Thumbs Up
    Received: 4
    Given: 3
    Total Downloaded
    977.98 MB

    0 Not allowed!

    Default Re: Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop worki

    Quote Originally Posted by Dave Purola View Post
    I have to ask, Why are you manipulating the ANSELA each time you enter the AD_Conv routine? This can be set once before the main loop. Also why are you turning off the A/D converter module each time you exit the AD_Conv routine?
    The device is battery-operated - saving energy.

  10. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Junior Member SebaG's Avatar
    Join Date
    Sep 2013
    Posts
    27
    Thumbs Up
    Received: 4
    Given: 3
    Total Downloaded
    977.98 MB

    0 Not allowed!

    Default Re: Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop worki

    Quote Originally Posted by flosigud View Post
    Did you resolve this?
    Unfortunately not.

  12. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,225
    Thumbs Up
    Received: 371
    Given: 131
    Total Downloaded
    1.58 GB

    0 Not allowed!

    Default Re: Prescaler divider other than 1:1 causes the PWM module in PIC10F322 to stop worki

    I've just changed the code a little and created a Setup subroutine for the CCP and ADC, and in the Isis simulator it is working at lower frequencies, as I don't have an actual device to test, however with such a simple piece of code, I know the simulator is working fine. The program below is giving a PWM at 489Hz:

    Code:
        Device = 10F322
        Declare Xtal = 4
        
        Config FOSC_INTOSC, BOREN_OFF, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, LVP_OFF, LPBOR_OFF, BORV_LO, WRT_OFF
       
        'Dim ADC_Raw As Byte
    
    '============================================================================================== 
    Main:
      
        Setup()
        Do
            'ADC_Raw = AD_Conv()
            PWM_1(50) 
        Loop
    
    
    '==============================================================================================
    Proc Setup()
        OSCCON = $50                                                                                                                                                                             
        TRISA = $04
        PORTA = $00
    
        PR2 = 127  '63
        TMR2 = 0
        T2CON = 7 
        PWM1CON = $C0
    
        ANSELA = $04                                                                    
        ADCON = $28                                                                     
        
        ADCONbits_ADON = 1
    EndProc
        
    '==============================================================================================
    Proc AD_Conv(), Byte                                                                                                                                                     
        DelayUS 20
        ADCONbits_GO_DONE = 1                                                              
        While ADCONbits_GO_DONE = 1                                                    
        Wend                                                                             
        Result = ADRES                                                                                                                                                                                                    
    EndProc
    
    '==============================================================================================
    Proc PWM_1(pDuty As Word)                                                                              
        PWM1DCL.6 = pDuty.0
        PWM1DCL.7 = pDuty.1
        PWM1DCH = pDuty >> 2    
    EndProc
    However, once the frequency is altered so does the resolution of the PWM, so you will need to read the datasheet and calculate the resolution for the PR2 and Timer2 settings. One of the problems with your original code may have been that you were disabling Timer2 with a value that clears bit-2 of T2CON. Also, your PWM_1 subroutine was adjusting SFRs that didn't need adjusting, as was the AD_Conv.
    Last edited by top204; 7th June 2019 at 23:13.

  14. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Pic10f322
    By Dphil7532 in forum Proton Plus Compiler v3
    Replies: 12
    Last Post: 2nd March 2013, 22:07
  2. Compiler stop working. Please, help me
    By hobbykit in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 1st September 2010, 09:14
  3. 18F1330 PWM Module
    By peaps in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 25th April 2008, 21:48
  4. Stop the pic working
    By sgufa in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 5th July 2007, 21:48
  5. interrupts prescaler problem
    By Dphil7532 in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 20th January 2006, 19:21

Members who have read this thread since 13th June 2019, 02:38 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts