HI
I have a program here, I guess it is somewhat working. I get a very erratic output, I need a steady frequency with a varying duty cycle. What I see on the scope is varying duty cycle frequency going in all direction, without me touching the circuit. I have set a pot on analog pin 1 . I can see the voltage varying from 0 to 5 with the multimeter , so this is working, I have a 47k on the MCLR pin and 22pF cap on the 20Mhz oscillator. Can somebody see the problem,
I may have gotten the initialization wrong or something like it
Thanks
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 AN6 (RA1) as analog, others to digital
ADCON1.7 = 1 ' 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,DutyCycle,10500
GOTO Mainloop
end
Bookmarks