Ya thats it, ADCON1.7 = 0
works fine
thanks skimask
K
Hi
works better with cap.
Although I still have problem with the HPWM. I decided to put a value in for the duty cycle, and I am not getting the right duty cycle out. I mean it is going from 10 to 80% to 50%, its all over the place:
INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
@ DEVICE pic16F88, HS_OSC , CCPMX_ON
DEFINE OSC 20 'use external 20mhz crystal
PAUSE 100 ' start-up delay
'/////////////////////////
'// PIN configuration //
'/////////////////////////
DEFINE CCP1_REG PORTB 'Define output port of pulses out
DEFINE CCP1_BIT 3 'Define output port of pulses out
Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
CMCON = 7 ' Disable analog comparator
ANSEL = %00000010 ' set AN1 (RA1) as analog, others to digital
ADCON1.7 = 0 ' Right justified results... duh... really needed in 8 bits???
ADCON0 = %11000001 ' Configure and turn on A/D Module
TRISB = %00000000 ' Set PORTB to all output
TRISA = %11111111 ' Set PORTA to all input
'///////////////////////////////////////////////
'// Variable Declaration and initialization //
'///////////////////////////////////////////////
DutyCycle var byte 'Create adval to store result
'//////////////////////////
'// Program starts here //
'//////////////////////////
Mainloop:
ADCON0.2 = 1 'Start Conversion
ADCIN 1, DutyCycle 'analog pin 1 get the 8 bit result
HPWM 1,166,10800
GOTO Mainloop
end
Don't keep overwriting the duty cycle value. Just write it once and let it run unless it changes.
If you look at the datasheet, you'll see that a few things tend to reset themselves whenever the duty cycle register is written, thereby screwing up your duty cycle.
I just tested the program above to test the HPWM command, in reality I want to use the following:
Mainloop:
ADCON0.2 = 1 'Start Conversion
ADCIN 1, DutyCycle 'analog pin 1 get the 8 bit result
HPWM 1,DutyCycle,10800
GOTO Mainloop
end
but even with
HPWM 1,166,10800
I am not getting the right duty cycle.
Do I need to define HPWM1_TIMER?
k
What are you getting for an output?
Skip the ADC for now, and just run a HPWM command, nothing else, with a duty cycle of 127. Should output a nice clean 50% on, 50% off square wave.
Hi, Ken
Just change the dutycycle IF there's a change in ADC result ...
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 " !!!
*****************************************
Bookmarks