Model Train controller - revisited


Closed Thread
Results 1 to 33 of 33

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Glug.. help ! glug glug... I'm drowning...... this is way over my head

    As far as I recall Darrels routines are software PWM and not Hardware ? However having said that I have not tried all channels at the same time to control two independant tracks.....

    On the subject of frequencies... when using a 4 Mhz xtal the rate at which the pulses are sent is quite noticeable at slow speed as each pulse is sent causes the model to "jump" at each step. Using a 20Mhz Xtal this is less noticable. When we were trying different settings, higher frequencies (estimated at around a few Khz ) were produced and the armature sang as the model made its way down the track.

    Steve hit on the subject of a frequency higher than the ear can hear, but I'm wondering if these pulses were sent at say 30Khz, the loco would start to see them as almost a constant voltage level. Its a bit irrelevent as under the settings in Darrels code, I can't get a frequency higher than 260 hz with two channels when running the 16f767 with a 20 mhz xtal.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As i said, i worry about such high frequency for this type of motor which are usually drive in 'pure-dc'. Maybe something to try... but for long term... i really can't say what could happen. One more reason why i posted a possible solution schematic... kind of linear regulation, sort of.

    But first, have all your loco available and try with <300Hz. HPWM and/or SSPWM.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    The only thing I couldn't work out with your op amp schematic, is where the power for the motor comes from as it shows the supply connected across the motor

    Smoothing capacitors across the output helps with the harshness of the PWM, and I'll try using a diode in parallel with the motor, but won't that effectively short the output to gnd ?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Oh yeah, my mistake.. anyways, the power is suppose to be attach to the Op-amp and transistor Collector. This work, but it may (will) heat much.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post

    A look to µChip AN 1074 ... ??

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Question Build failed !!!

    Hi, Malc

    I tried to compile your project and get a strange error at compiling : PIR2 not found ...

    which is the processor you use ? 767 or 676 ???
    and is the posted "twin track controller" your source ???

    the SPWM might run properly ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I'm using the 16F676 - this is the code that I have (I think its the same as per the 1st post in this thread)

    Code:
    @ __CONFIG  _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF 
    
    DEFINE OSC 20
    
    ANSEL = %00010111    			        ' Set which ports are digital and which are analogue
    CMCON=7                                 ' Turm Comparitors off
    TRISA=%11111111        			        ' set PORTA as all input 
    TRISC=%00000001        			        ' set PORTC as all output apart from RC0
    
    DEFINE ADC_BITS  8     			        ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 2     			        ' ADC clock source  (Fosc/32)
    DEFINE ADC_SAMPLEUS 11 			        ' ADC sampling time (uSec)
    
    INCLUDE "DT_INTS-14.bas"            	' Base Interrupt System
    INCLUDE "SPWM_INT.bas"              	' Software PWM module
    
    DEFINE SPWM_FREQ  150                	' SPWM Frequency (Hz)
    DEFINE SPWM_RES   254               	' SPWM Resolution (0 - 255)
    
    DutyVar VAR byte[4]                     ' Array used to store ADC [channels]
    
    ASM
    SPWM_LIST  macro                    	; Define Pin's to use for SPWM
        SPWM_PIN  PORTC, 2, _DutyVar        ; and the associated DutyCycle variables
        SPWM_PIN  PORTC, 3, _DutyVar+1      ; (Additional channels DutyVar+2, +3 etc)
      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, DUTYVAR[0]                    ; if having more channels add ADCIN 2, DUTYVAR[2] etc
     ADCIN 1, DUTYVAR[1]
    GOTO Main                               ; program simply loops round reading ADC and sending corresponding PWM out
    Compiles fine here

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. Graphics controller for the Sitronix ST7549
    By ttease in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th May 2007, 21:45
  4. Recommendations - Model Train Controller
    By malc-c in forum mel PIC BASIC Pro
    Replies: 101
    Last Post: - 8th March 2007, 08:17
  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