I've been trying to phathom out what I need to set ANSEL to or whats wrong with the code to get this to work 100%.
Referring to my post #74, I have three PWM outputs, but when I connect pot 4 to pin 10 and the corresponding output (pin 7 RC3) the loco just shoots off at full speed with no control - Here's the code
Here's hoping someone can point e in the right directionCode:@ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF ;ANSEL = %00010111 - dt suggested value ANSEL=%00110001 ; original CMCON=7 TRISA=%11111111 'set PORTA as all input TRISC=%00000001 'set PORTC as all output apart from RC0 DEFINE OSC 20 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 190 ; SPWM Frequency DEFINE SPWM_RES 255 ; SPWM Resolution 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] DutyVar4 VAR DutyVars[3] ASM SPWM_LIST macro ; Define Pin's to use for SPWM SPWM_PIN PORTC, 2, _DutyVar1 ; and the associated DutyCycle variables SPWM_PIN PORTC, 5, _DutyVar2 ; Notice the underscore before variables SPWM_PIN PORTC, 4, _DutyVar3 SPWM_PIN PORTC, 3, _DutyVar4 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, DUTYVAR1 ADCIN 1, DUTYVAR2 ADCIN 2, DUTYVAR3 ADCIN 4, DUTYVAR4 GOTO Main




Bookmarks