OK I thought, lets move this on and use a PIC capable of providing all 4 seperate PWM outputs. So after consultation via a few PMs with Steve and Darrel I've opted for a 16F676.
I've used a 20Mhz xtal, with 22pf caps between pins 2 and 3, wiper from 10K pot goes to pin 13 and PWM output on pin 8.
I've modified the code used for the 12F675, and compiled - no errors or warning, and loaded it into the PIC.
Code:
@ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF
ANSEL=%00110001
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 100 ; 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, 3, _DutyVar2 ; Notice the underscore before variables
SPWM_PIN PORTC, 4, _DutyVar3
SPWM_PIN PORTC, 5, _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 3, DUTYVAR4
GOTO Main
I then tested the code / hardware and I don't get the same performance as I did with the 12F. There is no responce from the loco until the pot is at mid point, at this stage the armature sings with a high pitch noise. Advancing the pot increases the speed, but I don't get anywhere like the slow crawl speeds I got with the 12F. I can also assume that the armature is warming as it smelt a little (carbon smell) after a short run.
I think its probably down to my poor understanding of Ansel etc.. so an constructive comments would be welcome.
Oh and I've not changed the driver stage yet as Alain suggested.
EDIT:: EDIT::
Changed the Xtal for a 4Mhz and the frequency of the noise has dropped.. but its still there and not the low growl that was produced by the 12F.. so it it a timing issue ??
Bookmarks