Hi, Ken
Just change the dutycycle IF there's a change in ADC result ...
Alain
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 " !!!
*****************************************
oK I will try this when I get home tonight.
I did some change in my program, mostly in the Pin Configuration section.
If this do not work, I will remove all the ADC stuff and just try the HPWM
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 = %00000000 ' Left justified results in 8 bits
ADCON0 = %10000001 ' 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 (RA1) get the 8 bit result
pause 50
HPWM 1,DutyCycle,10800
pause 100
GOTO Mainloop
end
Maybe try this instead:
Code: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 100 ' Set sampling time in uSec CMCON = 7 ' Disable analog comparator ANSEL = %00000010 ' set AN1 (RA1) as analog, others to digital ADCON1 = %00000000 ' Left justified results in 8 bits ADCON0 = %10000001 ' 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 LastDutyCycle var byte 'hold last time around '////////////////////////// '// Program starts here // '////////////////////////// Mainloop: ADCON0.2 = 1 'Start Conversion ADCIN 1, DutyCycle 'analog pin 1 (RA1) get the 8 bit result pause 50 If dutycycle <> lastdutycycle then lastdutycycle = dutycycle HPWM 1,DutyCycle,10800 Endif GOTO Mainloop end
I'm guessing that whenever this is executed:
PBP is stopping, setting up and restarting the HPWM.Code:HPWM 1,DutyCycle,10800
If you do this in the loop,
then your problem should go away. I don't know if PBP allows you to do this. If not, you will have to set up the hardware manually.Code:CCPR1L = DutyCycle
Code:PR2 = 462 '10,800Hz frequency CCPR1L = 0 'Initial duty cycle CCP1CON = %1100 'PWM mode T2CON.2 = 1 'Start TIMER2
I tried the following program, very simple, still not getting anything out..
using internal osc, trying to cut down on the hardware...
'Test HPWM command
'
INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
@ DEVICE pic16F88, CCPMX_ON, INTRC_OSC_NOCLKOUT
OSCCON = %110 ' Set OSC TO 4MHZ 'select the clock
'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
CMCON = 7 ' Disable analog comparator
TRISB = %00000000 ' Set PORTB to all output
TRISA = %11111111 ' Set PORTA to all input
'///////////////////////////////////////////////
'// Variable Declaration and initialization //
'///////////////////////////////////////////////
'//////////////////////////
'// Program starts here //
'//////////////////////////
HPWM 1,126,3000
PAUSE 200 ' delay
Mainloop:
GOTO Mainloop
end
I am looking at B.3 through my scope.
I am using the same hardware as my digital thermometer now, which was using B.3 to get the temperature and have a LCDout. (and that circuit is working fine, but no a/d or HPWM)
So I removed that wire on B.3 (of course) , placed the new chip in place and I am not seeing anything to the scope
k
Bookmarks