PDA

View Full Version : HPWM fails...



f_lez
- 24th March 2010, 16:12
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.






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

Charles Linquis
- 24th March 2010, 22:59
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.

f_lez
- 25th March 2010, 11:26
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......

Archangel
- 26th March 2010, 04:32
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.