Alain, thanks for the life saving ring... its keeping me afloat
OK I have something that works... but its not as smooth as the PWM command in PBP.
This is the code, based on the sample taken from Darrel's website. Using a 12F675
The output is quite pulsed, and moving the pot produces rather stepped increase in brightness rather than a smooth increase. Also the range of the brightness is limited to 2/3 the travel of the POT (unlike when I used the PWM command when it was right across from one end to the other)Code:@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON DEFINE OSC 4 CLEAR DEFINE ADC_BITS 8 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "SPWM_INT.bas" ; Software PWM module DEFINE SPWM_FREQ 40 ; SPWM Frequency DEFINE SPWM_RES 256 ; SPWM Resolution D var byte DutyVars VAR BYTE[3] ; DutyCycle Variables DutyVar1 VAR DutyVars[0] ; group them in an array for easy access DutyVar2 VAR DutyVars[1] ; with FOR loops etc. DutyVar3 VAR DutyVars[2] ASM SPWM_LIST macro ; Define Pin's to use for SPWM SPWM_PIN GPIO, 0, _DutyVar1 ; and the associated DutyCycle variables SPWM_PIN GPIO, 1, _DutyVar2 ; Notice the underscore before variables SPWM_PIN GPIO, 2, _DutyVar3 endm SPWM_INIT SPWM_LIST ; Initialize the Pins ENDASM ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, SPWMhandler, ASM, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts ;_____________________________________________________________________________ Main: ADCIN 0, D DutyVar3 = D GOTO Main
The waveform is different to that previously found when using the PWM command, as can be seen by the two images attached (one low, one high)
I assume the PWM settings in Darrels code can be changed by altering the values of
I'll play with the values and see if anything improves - Thanks for your help on thisCode:DEFINE SPWM_FREQ 40 ; SPWM Frequency DEFINE SPWM_RES 256 ; SPWM Resolution
EDIT:
Changing the OSC to 20 and freq to 100 gives less flicker, but the transitions are still not smooth... I also think that I need to come up with some driver circuit for the FET or feed the PIC outout into a Darlington pair arrangement with a power tranny reather than a FET





Bookmarks