Updating HPWM frequently, safe?


Closed Thread
Results 1 to 40 of 79

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    I removed that line from Darrel code and its clearly more stable now, but it still flickers at the lower range of the pot... very strange...

    I just modified the code I posted to write to eeprom the lowest pot setting where its stable, the read value was from $007B to $007C but I recorded a couple of $007F and $0068 after 125 readings/writes, my guess for these oscillations was someting in the write cycle because after I stopped reading the led went to steady again, I wish I had a scope...

    modified code:
    Code:
    if calibrapin=1 then
    if conta < 250 then
     write conta, pote.byte1
     write conta+1, pote.byte0
     conta=conta+2
    endif
    endif

    Pablo

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


    Did you find this post helpful? Yes | No

    Default

    Strange indeed.

    Well, I've made the changes Steve found and posted it at the same link.

    I won't get my scope back till wednesday. (should have waited)
    But I'll sure have a good look at it then.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    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?
    Steve

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

  4. #4
    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. #5
    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. #6
    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. #7
    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. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    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 " !!!
    *****************************************

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    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 " !!!
    *****************************************

  10. #10
    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

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    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 " !!!
    *****************************************

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    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 " !!!
    *****************************************

  13. #13
    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

  14. #14
    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

  15. #15
    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

  16. #16
    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

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 : 0

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