HPWM fails...


Closed Thread
Results 1 to 4 of 4

Thread: HPWM fails...

  1. #1

    Default HPWM fails...

    Well not fails, but seem to behave odd...

    if i create a simple for-next with a byte variable and out it the channel 1 or 2, with led's connected, the leds raise in brightness 3 (yes three) times for the loop!

    I am using USB with DT interrupts, and ADC on ra0/ra1, idea was the adc value of ra0/1 woul;d pwm the outputs on channel 0/1



    Is there any defines I should be looking at etc or anything else i can post to help?

    18f2550, at 4mhz, pll div 1 OSC 48 etc.



    Code:
    DEFINE HSER_RCSTA	90h
    DEFINE HSER_TXSTA	20h    ; 24 is giving error
    DEFINE HSER_BAUD	9600
    ' DEFINE HSER_SPBRG	25  ' let picbasic set it from the baud def above
    DEFINE HSER_EVEN	1
    
    DEFINE CHAR_PACING 1000   ' slow things a little
    
    DEFINE HSER_CLOERR  1 ' automatic clear overrun error
    
    
    
    DEFINE ADC_CLOCK 1
    DEFINE ADC_BITS 8
    DEFINE ADC_SAMPLEUS 10
    
    ADCON1 = %10000011 ; not sure lol
    CMCON = 7 ;  Disable Comparators
    
    INTCON2.7 = 0 ; should enable portb pullups.
    
    
    for tempx=0 to 255
    
    
    HPWM 0,tempx,1000
    hpwm 1,255-tempx,1000
    
    portb=tempx
    
    pause 125
    next

    maximu brightness is at 87 and 174, not 255....

    any ideas what could be causing this looping?


    edit: user error, time to RTFM...

    freq too low for clock speed...
    Last edited by f_lez; - 24th March 2010 at 16:43.

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I'm trying to figure out what you mean by -

    "18f2550, at 4mhz, pll div 1 OSC 48 etc."

    Is your device running at 4Mhz, 16Mhz, 48Mhz or some other speed?


    Whatever speed it is running, that is what the

    DEFINE OSC xx line should state.

    The code has no idea of what speed oscillator you are using, so you have to tell it in order for PBP to set things up correctly.
    Charles Linquist

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    I'm trying to figure out what you mean by -

    "18f2550, at 4mhz, pll div 1 OSC 48 etc."

    Is your device running at 4Mhz, 16Mhz, 48Mhz or some other speed?


    Whatever speed it is running, that is what the

    DEFINE OSC xx line should state.

    The code has no idea of what speed oscillator you are using, so you have to tell it in order for PBP to set things up correctly.
    The crystal is 4mhz, the pll div /cpu div is set to 1, which cloccks the pic at 48mhz, the define osc is set to 48, which is all correct, the error was in the limitations of the minmum freq of the pwm at that clock speed, i had forgot to check, never imagined that the slowest i could run it was 3k at that clock, hence the three levels of brightness for 0-255, not a simple one level

    I didnt rtm......

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Try it using word variables or lower the 255 by 1 0r 2, I have had problems with bytes and 255, I usually will just use words and make sure there is an error handler if they go over 255, something like if yourvar > 255 then yourvar = 255.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Members who have read this thread : 1

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