Recommendations - Model Train Controller


Results 1 to 40 of 102

Threaded View

  1. #29
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Sorry I missed that... I've remmed out the PWM line fro GPIO.0 and have got a reasonable result, especially for slow speed - The crawling speed of an 18 year old tank loco is really amaizing !!

    Here's the code

    Code:
    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   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
    Using a close loop fedback output stage and a 12v regulated supply for the track as per the diagram attached, I get a nice smooth slow speed control. This is using the 12F675 with its internal osc.

    The loco does growl a bit when at really slow speed... and at maximum speed its fine for a goods train, but not an express. I susspect that using a higher track supply voltage will resolve the speed issue (my DVM reads 6.5v across the track at full speed), but wondered if there was anything I could do to reduce the growling at slow speed.

    Please bear in mind that I'm still somewhat new to PICs and programming.. so If I've still overlooked something in the settings then please advise what I did wrong and how to correct it.
    Attached Images Attached Images  

Similar Threads

  1. Microstepper controller
    By aratti in forum Schematics
    Replies: 14
    Last Post: - 3rd January 2015, 16:52
  2. problem with the GSM controller
    By Dariolo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th May 2009, 20:33
  3. Replies: 2
    Last Post: - 14th July 2008, 22:11
  4. Model Train controller - revisited
    By malc-c in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 8th May 2007, 09:40
  5. Dedicated LCD Controller question
    By chuckles in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th February 2006, 14:44

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts