Updating HPWM frequently, safe? - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 79 of 79
  1. #41
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    Great thread this.
    Last edited by T.Jackson; - 7th May 2007 at 06:32.

  2. #42
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    O.K. i'll stop here... at least by respect to our members and readers, and because it's not a chit-chat area.
    Last edited by mister_e; - 7th May 2007 at 04:55.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #43
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    ...deleted...for obvious reasons
    Last edited by skimask; - 7th May 2007 at 04:59.

  4. #44
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    mmm, could be a noisy pot as well... using your code and on many low-value ADC.. they are all stable.. no noise, no frlicker.

    what happen if you stick a 0.1 uF in parallel with your POT wiper?

    Any 0.1uF + 10uF capacitor close to your PIC?
    I just tried with a 20 turn 10k linear pot and its the same, once I reach the lower duty cycles the led flickers.
    The difference is clearly visible with the multiturn pot, once you go below a certain level it flickers, move the other way a little bit and the flicker goes away

    Reading in the flicker position I get this range: from $00BB to $00BF and spurious $009F , $00B4, $00C6, $00E3 at random places
    Reading in the steady position I get this range: $00CD to $00CF and no spurious readings

    I only read 125 word values into the device own eeprom.
    Again Im using a li-ion battery for powering the circuit (3.65v)

    Weird isnt it? even weirder is that sometimes when I write the values to eeprom the written values are steady (also visually) but only when writting...

    Just in case here is the code I used:
    Code:
    '       Pic Configuration
    @ device pic12f683,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_off        
    
    '       Hardware configuration
    
    '       I/Os
    TRISIO = %00010010      ' pin1 is ADC , pin4 is the calibration button
    
    '       ADC's
    ANSEL = %00000010  
    DEFINE ADC_BITS 10      ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 1      ' ADC clock source  (Fosc/8)
    DEFINE ADC_SAMPLEUS 11  ' ADC sampling time (uSec)                      
    ADCON0.7 = 1            ' Right justified results
    
    '       Comparator
    CMCON0 = %00000111     ' Disable comparator
    VRCON  = %00000000     ' disable
    'cmcon0 = %00001110      ' Multiplexed Input with Internal Reference CIS=1
    'vrcon  = %10001010      ' set vref=2.25v (from 4v input) 
    
    include "HPWM10.pbp"
    
    ' definitions
    pote 		var word
    Frequency   var word
    calibraled  var gpio.5
    calibrapin  var gpio.4
    conta       var byte
    
    gpio=0
    conta=0
    frequency=1000
    pause 50    ' coffee break
    
    loop:
    
        adcin 1, pote
        if pote>1000 then pote=1000
        
    if calibrapin=1 then
    if conta < 250 then
     write conta, pote.byte1
     write conta+1, pote.byte0
     conta=conta+2
    endif
    endif
    
    @ HPWM10  1, _pote, _Frequency
    pause 10
    
    goto loop
    end

    Pablo

  5. #45
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    O.K. i have to go out. I had the same code, and i didn't have any problem...

    when i'll be back, i'll use a lower voltage AND use HighBrightness LEDs.

    Wish i could see the same thing....

    Still thinking there's an hardware problem...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #46
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Pablo,

    Good new, Bad news.

    I finally found my 12F683 and gave it a go.
    I've completely duplicated your problem. Blinking and all.

    For some reason it only does it on the 683.
    Every other chip I tried seems to work fine.

    And the bad news is, I haven't found out why yet. (Operative word, Yet)
    It appears to be with the A/D, the readings are all over the place at low voltage input.

    I still have many things to try, but just wanted you to know you're not crazy.
    And, I WILL find it. (unless somebody beats me to it)
    <br>
    DT

  7. #47
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by Darrel Taylor View Post
    Pablo,

    Good new, Bad news.

    I finally found my 12F683 and gave it a go.
    I've completely duplicated your problem. Blinking and all.

    For some reason it only does it on the 683.
    Every other chip I tried seems to work fine.

    And the bad news is, I haven't found out why yet. (Operative word, Yet)
    It appears to be with the A/D, the readings are all over the place at low voltage input.

    I still have many things to try, but just wanted you to know you're not crazy.
    And, I WILL find it. (unless somebody beats me to it)
    <br>
    As I see it its only good news Thanks for all your efforts!!!

    I can't help with your code, is way beyond my actual knowledge, I hope to catch up with it in the future!

    Now I patiently wait


    Pablo

  8. #48
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    An EE friend of mine (Thanks Doug) told me a new possibility about the cause of the problem:

    What if reading the ADC so often does not give it enough time to handle the low voltage values?

    (more discussions via chat with my friend)

    He points out something interesting, the test program initializes the ADC using:

    DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
    DEFINE ADC_CLOCK 1 ' ADC clock source (Fosc/8)
    DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)

    But reading the pic basic manual we have:

    ADC_SAMPLEUS is the number of microseconds the program waits
    between setting the Channel and starting the analog to digital
    conversion. This is the sampling time. The minimum number of
    microseconds usable is determined by the minimum time for PAUSEUS.
    See it’s section for this information.
    and the PAUSEUS section says:
    For 4mhz Minimum Delay is 24us
    So, the initial theory appears to be right, I don't have the protoboard here now, but I will check this tomorrow.


    Pablo

  9. #49
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I tried every AD oscillator / Sample time possible, and it made no difference.
    Even with the A/D input tied directly to ground, it was getting crazy readings between 0 and 20.

    After I tried it with a 12F675 (without the CCP) and got the same results,
    I finally figured out that I had removed the big cap on the power lines on this protoboard.
    Probably needed it for something else. Doh!

    After putting a 100uf cap across the power supply, everything calmed down again.
    It's still not perfect, but I think that has alot to do with the breadboard.

    So then to really stabilize things I added an averaging routine, and I think that's about as close as we're going to get.

    First make sure you have enough capacitance on your power lines (I think mister_e already suggested that).

    Then add this to the bottom of the program
    Code:
    ' -=-=-=-=-=-=  Average Analog values -=-=-=-=-=-=-=-=-=-=
    Avg       VAR WORD
    AvgCount  CON 16
    spread    CON 20
    
    Average:    ' Smooth data
        IF ABS (pote - Avg) > spread then
            Avg = pote
        else
            Avg = (Avg*(AvgCount-1)+pote)/AvgCount 
            pote = Avg                               
        endif
    Return
    And also, just after the ADCIN statement, add this
    Code:
        gosub Average
    HTH,
    DT

  10. #50
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it's getting interesting... i have everything on hand, will do some test here.

    Sorry, i was suppose to do it yesterday
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #51
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    well I hope you find something because I tried adding a 100uF capacitor in the power lines or in parallel with the wiper and my problems remain, even after adding the averaging routine provided by Darrel.

    I even started looking for other pic alternatives in case this can't be solved...

    Thanks again

  12. #52
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    still working @ 3.x Volt?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #53
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    yes Sir, using a 3.6v li-ion batt


    Pablo

  14. #54
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    O.K. can you try to program you pic with the .HEX in attachment and let me know what's happening now?

    Finger crossed...
    Attached Files Attached Files
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #55
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    O.K. can you try to program you pic with the .HEX in attachment and let me know what's happening now?

    Finger crossed...
    it uses the circuit I provided right? will test it tomorrow and let you know. Thanks!!!

  16. #56
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yup it's the same circuit. CalibraPin is also implemented.

    Here, it's working, no flicker or else... 'till now
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  17. #57
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    yes it flickers, but this one instead of graduating continuously goes in steps, and the calibrapin button does nothing, at least nothing I can see or read.

    Thanks!

  18. #58
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    can you try something because it's working really fine here... use another ADC channel, like GP4, or GP5.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  19. #59
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    can you try something because it's working really fine here... use another ADC channel, like GP4, or GP5.
    what do you mean by using another ADC? change the my test program to read in another port ?

    thanks

  20. #60
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    In your example you used ADCIN 1,pote to read GP1. Change it to ADCIN 5,pote. Sure you'll need to change your hardware and some regisers settings as well.

    Next step will be to use a TIMER interrupt instead.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  21. #61
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    In your example you used ADCIN 1,pote to read GP1. Change it to ADCIN 5,pote. Sure you'll need to change your hardware and some regisers settings as well.

    Next step will be to use a TIMER interrupt instead.
    I will do two things, 1st etch a pcb for the circuit and test it again, second try with a 16F628A

    I let you know. thanks!

  22. #62
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    made the etched pcb and only tried it with Mister_e hex file and it worked without flickerings. Im not sure if its supposed to smooth or in steps, I see steps.

    More tests on monday. Thanks!!

  23. #63
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    steps are normal with my HEX. but good news! and thanks to report your results. Sure many code before my last one will now work as designed.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  24. #64
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Question HPWM10 Question

    Hi, Darrel,

    I just try tu make HPWM10 work aboard a 12F683 ...

    and get the following Message ( MPASM compiler ) :

    Error[108] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\SPEEDCOMM.ASM 185 : Illegal character (1)

    the illegal character is ... the PWM Channel !!!

    @ HPWM10 1, _DutyCycle, _Frequency

    I used the example " straight out of the box ...

    do you have any idea ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  25. #65
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb THE Idea

    re,

    The idea is : change "HPWM10.pbp" into "HPWM.bas", for the include command.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  26. #66
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Error[108] C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\SPEEDCOMM.ASM 185 : Illegal character (1)
    There had to be more errors than that.
    The others might have had more clues, but it appears that PBP couldn't find the file.

    Are you saying that you renamed it to HPWM.bas but still had INCLUDE "HPWM10.pbp"?

    confused.
    <br>
    DT

  27. #67
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by Darrel Taylor View Post
    There had to be more errors than that.
    The others might have had more clues, but it appears that PBP couldn't find the file.

    Are you saying that you renamed it to HPWM.bas but still had INCLUDE "HPWM10.pbp"?

    confused.
    <br>
    Hi, Darrel,

    Hoooo ... bad evening ! was HPWM10.pbp into HPWM10.bas.

    the goal was to transform a R/C pulse into a corresponding 10 bits PWM @ 10 kHz ... and drive a "Diesel engine" sound machine.

    Have a nice week end.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  28. #68
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Red face

    Hi, Darrel

    I Was a bit surprised by those lines :

    Code:
     Line    Address    Opcode        Label                    Disassembly              
    
        359     166       00BD                    MOVWF 0x3d                             
        360     167       084C                    MOVF _HP_Channel, W                    
        361     168       3C05                    SUBLW 0x5                              
        362     169       1C03                    BTFSS STATUS, 0                        
        363     16A       2975                    GOTO L00001                            
        364     16B       3001                    MOVLW 0x1                              
        365     16C       008A                    MOVWF PCLATH                           
        366     16D       084C                    MOVF _HP_Channel, W                    
        367     16E       0782                    ADDWF PCL, F                           
        368     16F       297A                    GOTO _GetCH_2                          
        369     170       2975                    GOTO L00001                             
        370     171       297A                    GOTO _GetCH_2                          
        371     172       297A                    GOTO _GetCH_2                          
        372     173       297A                    GOTO _GetCH_2                          
        373     174       297A                    GOTO _GetCH_2                          
        374     175       0813   L00001           MOVF CCPR1L, W                         
        375     176       00C0                    MOVWF _HP_Temp                         
        376     177       0815                    MOVF CCP1CON, W                        
        377     178       00C1                    MOVWF _HP_Temp??HIGHBYTE               
        378     179       297A                    GOTO _GetCH_2                          
        379     17A       0840   _GetCH_2         MOVF _HP_Temp, W                       
        380     17B       00A0                    MOVWF BANK0_START                      
        381     17C       01A1                    CLRF 0x21                              
        382     17D       3002                    MOVLW 0x2                              
        383     17E       205A                    CALL SHIFTL
    are those 6 times " GOTO _GetCH_2 " ( L368 , 370 - 373 , 378 ) something " regular " ???


    the source for 12F683 @ 8 Mhz internal is :

    Code:
    @ __config _INTRC_OSC_NOCLKOUT &_FCMEN_OFF &_IESO_OFF & _WDT_ON &_PWRTE_ON & _MCLRE_OFF & _CP_OFF
    
     OSCCON = %01110111					' Internal Clock 8 Mhz
     
     CMCON0 = 7
     VRCON  = 0
     ADCON0 = 0
     ANSEL  = 0
    
     DEFINE OSC 8                   	'Declare 8 Mhz operation 
     DEFINE PULSIN_MAX 4500
    
     
    ' PINS DEFINITIONS
    
    	Signal	var GPIO.3
    	Drive	var GPIO.2
    	
    	GPIO	= 0	
    	TRISIO 	= %00001000
    
    	
    ' VARIABLE DEFINITIONS
    
      	speed     	var Word              	' assign Word variable to speed demand
      	w1			var Word				' Table	output
      	
      	DutyCycle  	VAR WORD
    	Frequency 	VAR WORD
    	Temp       	VAR WORD	
    		
    
    	include "HPWM10.bas"
    
    	LOW Drive  ; Set CCP1 pin to output low
    
    	Frequency = 10000
    
    '******************************************************************************
    'MAIN LOOP
     main:
      
    
       pulsin Signal,0,speed				' Read servo pulse ( Inverted !!! ) 
               
    '******************************************************************************
    ' Throttle amount topped to 100 and reduced to 25 steps
      
       if speed > 300 then
         speed = ( speed - 300 )MIN 100
       else
         speed = ( 300 - speed )MIN 100
       endif
        
       speed = speed >> 2
       
    '******************************************************************************
    ' Conversion logarithmique 10 bits - 800 maxi à 10 khz
    
    	
    	lookup2 speed, [0,0,161,277,378,467,543,611,670,721,766,804,836,867,893,_
    	 933,950,965,978,990,1000,1009,1017,1023,1023 ],w1                     	                     
    
    '******************************************************************************           
    ' !!! Passer en " HPWM 10 " !!!
    
        if w1 <> DutyCycle then  DutyCycle = w1
        
        @ HPWM10 1, _DutyCycle, _Frequency  
         
       goto main
    
    END
    Regards

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  29. #69
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Darrel

    I Was a bit surprised by those lines :
    ...
    are those 6 times " GOTO _GetCH_2 " ( L368 , 370 - 373 , 378 ) something " regular " ???
    The lines showing the same labels is the result of Disassembling.
    There are actually 6 different labels, with the code in-between optimized out since the chip doesn't have 5 CCP modules.

    It comes from this section ...
    Code:
    ;-----  Get Current DutyCycle ------------------------------------------------
        Branch HP_Channel,[GetCH_Done,GetCH_1,GetCH_2,GetCH_3,GetCH_4,GetCH_5]
    
        GetCH_1:
                ASM
                  ifdef CCP1CON  
                    MOVE?BB  CCPR1L,  _HP_Temp
                    MOVE?BB  CCP1CON, _HP_Temp + 1
                    goto _GetCH_Done        
                  endif  
                endasm
        GetCH_2:  
                ASM
                  ifdef CCP2CON  
                    MOVE?BB  CCPR2L,  _HP_Temp
                    MOVE?BB  CCP2CON, _HP_Temp + 1
                    goto _GetCH_Done        
                  endif  
                endasm
    The GOTO's are created by the Branch statement.
    And it looks like this in the .LST file ...
    Code:
    016B   3001               M         movlw   (jmptbl) >> 8
    016C   008A               M         movwf   PCLATH
    016D   084C               M         movf    _HP_Channel, W
    016E   0782               M         addwf   PCL, F
    016F                      M jmptbl
    016F   297A               M         goto    _GetCH_Done
    0170   2975               M         goto    _GetCH_1
    0171   297A               M         goto    _GetCH_2
    0172   297A               M         goto    _GetCH_3
    0173   297A               M         goto    _GetCH_4
    0174   297A               M         goto    _GetCH_5
    0175                      M L00001
    0175                      M _GetCH_1
    0175   0813               M         movf    CCPR1L, W
    0176   00C0               M         movwf   _HP_Temp
    0177   0815               M         movf    CCP1CON, W
    0178   00C1               M         movwf   _HP_Temp + 1
    0179   297A           00326                 goto _GetCH_Done        
    017A                      M _GetCH_2
    017A                      M _GetCH_3
    017A                      M _GetCH_4
    017A                      M _GetCH_5
    017A                      M _GetCH_Done
    Since the labels are all at the same address, the disassembler chooses the first label it finds at that address (_GetCH_2).
    DT

  30. #70
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Smile

    Hi, Darrel

    Tanks for your explanation

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  31. #71
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32


    Did you find this post helpful? Yes | No

    Default 10 bit HPWM command on both CCP modules

    Hello,

    I would have two different frequency on CCP1 and CCP2 pin the first is 100HZ and second is 20Khz-40KHz. I use 1MHz quartz for clock and HPWM10 command from D.T. I use PIC16F876.
    I have on both CCP pin HPWM10 command with frequency 100hz and different duty. This working ok. When changed frequency on CCP1 to 1KHz then is frequency on both pin unchanged and very unstable
    When change one HPWM10 command to normal 8 bit HPWM then stay result unchanged.
    what I did wrong?

    here is first part of my program:




    INCLUDE "ALLDIGITAL.pbp"

    Cifra var byte
    Cifra1 var byte
    Maska1 var byte
    Maska2 var byte
    W var byte
    i var byte
    time var byte
    PR var byte
    VU var word
    VD var word
    Duty VAR word
    Duty1 VAR word
    FREQUENCY var word
    FREQUENCY1 var word

    LED var PORTC.4
    LEDDis1 var PORTA.0
    LEDDis2 var PORTA.1
    tipka1 var porta.2
    tipka2 var porta.3
    tipka3 var porta.4
    BUZ var porta.5
    enable1 var portc.0
    b0 var byte
    b1 var byte
    b2 var byte
    b3 var byte
    impulz var WORD
    minuta var byte
    key var byte
    pavza var word

    bp var byte

    TRISA=%11111100
    TRISB=%00000000
    TRISC=%00000000


    clear
    include "HPWM10.pbp"
    LOW PORTC.1
    LOW PORTC.2
    PWM_ON CON %00001100
    PWM_OFF CON 0
    time=6
    FREQUENCY=93 '
    FREQUENCY1=1000
    low led
    gosub zvok
    eeprom 0,[31]
    eeprom 2,[55]
    high enable1
    high led
    pause 100
    low led




    INTCON = %00100000
    OPTION_REG = %10001000

    On Interrupt Goto ISR
    INTCON = %10100000
    w=0


    Main:

    gosub tipka
    gosub timing
    read 0,b2
    gosub tpwm
    @ HPWM10 2,_IMPULZ,_FREQUENCY
    read 2,b0
    gosub ppwm
    @ HPWM10 1,_duty,_FREQUENCY1
    Gosub Priprava
    goto Main

    ppwm: b1=b0-50
    lookup2 b1,[100,200,300,400,500,600,700,800,900,1000],duty
    return

    tpwm: b3=b2-30
    lookup b3,[0,31,16,6,21,46],duty1
    return

  32. #72
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    With 16F876's, both CCP modules use the same Timer in PWM mode (TMR2).
    If you change the frequency of one, the other one changes too.

    With a 4 Mhz crystal, the minimum HPWM frequency is 245 Hz.
    Since you are using a 1 Mhz crystal, you can get down to 62 Hz, but you have to specify the frequency as if it were running at 4 Mhz.

    If you want 100 Hz, then specify 400 Hz in the HPWM10 command.
    93 is way below the minimum.
    <br>
    DT

  33. #73
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Frequency of 100 Hz is not a problem. In the case that I use PIC16F886 asking whether the command HPWM10 set timer TMR1 and TMR2 for each channel?
    Can you write the registry settings for the PIC16F886?

    tnx
    Samo

  34. #74
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Even on a PIC16F887, the CCP modules can only use Timer2 in PWM mode.
    So both PWM channels will operate at the same frequency.

    So I guess the answer to your question is ...
    HPWM10 only changes Timer2, not Timer1.
    <br>
    DT

  35. #75
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Whats required to have 'glitch free' operation but with 8 bit PWM, can the include file be easily modified for 8 bit, or should i just multiply my desired 8 bit dutycycle by 4?

  36. #76
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Also, just testing on 16F887, at 4mhz,

    @ HPWM10 1,_OUTDUTY,300 results in a PWM frequency of 10khz according to my o'scope ???
    I see the duty cycle changing, but the freq is around 9-10khz?

  37. #77
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The frequency must be a variable.
    You can't pass a constant as the parameter.

    And just shift left 2 (<<2) to use 8-bit values.

    hth,
    DT

  38. #78
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Angry Re: Updating HPWM frequently, safe?

    Old thread but very relevant to my issue.

    Can I use HPWM10:

    1. On an 18F87J50?
    2. And have it glitch free?
    3. To make a pulse train that's 140mS long and have varying duty cycles within the pulse train?

    In other words: 300uS on, 200uS off, 300uS on on, 200uS off, 130uS on, 370 uS off, 300uS on, 200uS off, 130uS on, 370uS off, 170uS on, 330uS off, 130uS on, 370uS off, etc.

    Each bit is 500uS and I don't need to modify anything while the packet is being sent; I can modify right before the next one is sent.
    Last edited by Christopher4187; - 16th June 2015 at 14:50.

  39. #79
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Updating HPWM frequently, safe?

    If by “glitch free” you mean free of any resolution error, not every frequency or duty cycle you want to generate will be.
    for any particular frequency, you need the pic’s clock frequency to tell you that.
    This online PWM calculator can tell you:
    http://www.micro-examples.com/public...alculator.html

    whether or not you can change it for arbitrary duration for every pulse like that would be a tough one,
    I don’t think that’s possible, but might be wrong.

    Depending what else the chip has to do, it might be possible to use timer1 overflow that way.
    Last edited by Art; - 18th June 2015 at 19:58.

Similar Threads

  1. need help on hpwm
    By helmut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 15:49
  2. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05
  3. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  4. HPWM and A to D interaction question 18F252
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th May 2006, 03:50
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

Members who have read this thread : 2

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