HI,
Wrote a short program to be able to input two ADCIN so I could have a variable duty cycle and variable frequency at my HPWM.
Duty cycle works fine, but the frequency output is very erratic,
example at 1v I get 500Hz
1.2v 2.2Khz
1.3v 300Hz
1.4v 620Hz
I mean the frequency is all over the place, , here is my code:
Any ideas ??Code:INCLUDE "modedefs.bas" 'Includes support for PicBasic language OSCCON = %01110000 '8 Mhz DEFINE OSC 8 CMCON = 7 ' Define ADCIN parameters 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 uS DEFINE CCP1_REG PORTB DEFINE CCP1_BIT 0 ANSEL = %00000011 ' set AN0 & AN1 as analog, others to digital ADCON1 = %00000010 ' Set PORTA analog and RIGHT justify result TRISB = %01000010 TRISA = %00000111 DutyCycle var byte Frequency var byte Mainloop: 'ADCON0 is binary '11000001' to read from AN0, and binary '11001001' to read from AN1. ADCON0 = %11000001 'Start Conversion pause 100 ADCIN 0, DutyCycle 'Read channel PORTA.0 Duty Cycle pause 30 ADCON0 = %11001001 'Start Conversion pause 100 ADCIN 1, Frequency 'Read channel PORTA.1 Frequency pause 30 HPWM 1,DutyCycle,Frequency 'channel, dutycycle, frequency pause 20 goto Mainloop END
thanks
ken




Bookmarks