
Originally Posted by
comwarrior
I've got HWPWM 1 (RC2/CCP1) feeding into TMR1 counter input (RC0/T1CKI).
I want the PWM set at 1KHz @ 50%...
You've turned on the Timer1 Oscillator (T1CON.3), which would be used if you had a 32khz crystal on Timer1.
For pulses on T1CKI the T1OSC needs to be turned OFF.
The CCP module has a minimum frequency of 1,465hz when using a 24mhz crystal. But you shouldn't be running a 16F877A at 24mhz anyway. The max is 20Mhz.
But even at 20mhz, the minimum PWM frequency is 1221hz.
The following line does absolutely nothing. It does NOT set the configs.
Which brings the question ... What are your CONFIGs set to?
Code:
Define CONF_WORD = $3F3A
The bs1defs.bas include file can help when trying to use a Basic Stamp 1 program with PicBasic Pro.
If you're writing the program from scratch in PBP, it's of no use.
Code:
include "bs1defs.bas"
8 bits is default to begin with. This line does nothing.
Code:
DEFINE SER2_BITS 8 ' Ser2 number of data bits
If you will be using ADCIN then you need to put the AD clock setting in the ADC_CLOCK define.
By setting the individual bits in ADCON0, they will be overwritten every time an ADCIN statement is used.
And PBP defaults to AD clock 3 (internal osc).
Code:
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_SAMPLEUS 100 ' Set sampling time in uS
ADCON0.6 = 1 ' ADC clock set to Fosc/64
ADCON0.7 = 1 ' ADC clock set to Fosc/64
ADCON1.6 = 0 ' ADC clock set to Fosc/64
Interrupts are automatically disabled on any Reset.
No need for this line.
Code:
INTCON = 0 ' Disable all interupts
Sets PORTA AND PORTE as Analog.
And yes, ADCON1 already defaults to 0.
Code:
ADCON1 = 0 ' PORTA is analog
You GOSUB to TMR1setup, then program execution "Falls into" the TMR1setup routine again.
When it hits the RETURN, the program will jump off into la-la land.
But maybe you just didn't include the parts in-between.
Code:
gosub TMR1setup
HPWM 1,127,1000
SEROUT2 PORTB.5,16390,["INITIALISED",10,13]
TMR1setup:
TMR1L = 0 ' reset TMR1 low to 0
TMR1H = 0 ' reset TMR1 high to 0
...
Bit's do not randomly turn themselves ON/OFF, and PIE1 defaults to all 0's on RESET.
If the bit wasn't set before (it wasn't) then there's no need to turn it off.
Code:
PIE1.0 = 0 ' Disable TMR1 interupt (double check)
Bookmarks