Recommendations - Model Train Controller


Closed Thread
Results 1 to 40 of 102

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Alain,

    I'm getting way out of my depth here. I downloaded the three files from Darrel's web site (http://www.darreltaylor.com/DT_INTS-14/SPWM.html) and copied the sample code for the LEDs. Darrel stated on the PBgroup that the code Works on just about any chip. 12F, 16F, 18F, but if I try compiling with MCS I get errors, regardless of the target pic selected.

    ERROR: variable wsave3 position request 416 beyond RAM_END 335

    I've never used other include files etc before, but if I understand his site correctly it should be a simple matter of downloading and saving the three files to the PBP folder, copy and pasting the sample code into MCS and then compiling ?

    Any ideas ?

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


    Did you find this post helpful? Yes | No

    Wink The long and winding road ...

    YESS

    Big Idea !!! just comment the faulty line ... as this location only exist in elephant memory Pics !!!

    also ... as stated in one of Darrel's further replies !!!

    Alain

    find it ... in the beginning of " DT int 14 .bas "

    ' --- IF any of these three lines cause an error ?? ----------------------------
    ' Comment them out to fix the problem ----
    ' -- It depends on which Chip you are using, as to which variables are needed --
    wsave1 var byte $A0 SYSTEM ' location for W if in bank1
    wsave2 var byte $120 SYSTEM ' location for W if in bank2
    wsave3 var byte $1A0 SYSTEM ' location for W if in bank3
    ' ------------------------------------------------------------------------------

    YOU DO NOT HAVE BANK3 in your Pic ... isn't it ???
    Last edited by Acetronics2; - 12th February 2007 at 12:51.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    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
    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 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)

    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
    Code:
    DEFINE SPWM_FREQ  40                ; SPWM Frequency
    DEFINE SPWM_RES   256               ; SPWM Resolution
    I'll play with the values and see if anything improves - Thanks for your help on this

    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
    Attached Images Attached Images   
    Last edited by malc-c; - 12th February 2007 at 14:10.

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Malc ...

    Think you change your Duty VERY frequently ( it's only a train ...not a jetfighter !!! ) ... so you could insert some PAUSE 100 - 300.

    Secondly, you also could change DUTY ... only if the POT result changes.( a little Hysteresis w/ ADC could be useful ??? )

    Third, you could insert a smooth duty transition ...

    like that :


    ....

    Dutyvar3 = 0

    Main:
    ADCIN 0, D

    IF D <> DutyVar3 THEN

    IF Dutyvar3 > D then Dtemp = Dtemp - 1 '( 1, 5, 10 ... as INERTIA needed ! )
    IF Dutyvar3 < D then Dtemp = Dtemp + 1

    DutyVar3 = Dtemp


    ENDIF


    PAUSE 200 '( to be trimmed ... 200 for 1 Channel, 100 for 2
    Channels ...)

    GOTO Main

    ... or something like that !!!

    Alain
    Last edited by Acetronics2; - 12th February 2007 at 14:28. Reason: skipped PAUSE ...
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default better result

    In a bid to get rid of the strange noise shown on the traces in previous posts I've tried using the pulseout command.

    Whilst its still not perfect as the pusle width can go down to zero, the resulting squarewave that the PIC outputs is a lot cleaner as can be seen by the attached image

    I'm going to get some power transistors tomorrow and develop the output stage based on a few examples I found in an old book I used some 25 years ago and see how it performs.

    Here's the code if anyone is interested.

    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
    TRISIO.2 = 0   'Set GPIO.2 to output.
    ANSEL.2 = 0    'Set GPIO.2 to digital		
    GPIO.0 = 1      'gpio.0 set to input
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    
    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
    
    D var byte
    
    main:
    ADCIN 0, D 
    PULSOUT GPIO.2 ,D                                  
    goto main
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Guys, thanks for your input to this idea, however I think I'll opt for a controller using descrete parts afterall. I played about with a few transistors and the FET and managed to get some control over a loco... the drawback was that the armature sang due to the frequency of the pulses !!

    Mind you I've learnt a bit more of PBP along the way, so it hasn't all been a waste of time

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm,

    Don't know anything about trains, but I can say with somewhat good confidence, that the waveforms you were getting are due to the Soundcard Oscilloscope.

    Sound cards have a capacitively coupled input, And most have a minimum of around 20hz that they can see. That's a 20hz sine wave, not a squarewave. When you changed to pulsout, you can see on your picture that the frequency went up to almost 2khz, so it was able to at least see the waveform, even though still inaccurately.

    I ran the program here (although on a different chip) and got a nice clean 40hz PWM.

    It looks like you've given up on the PIC idea already so I won't bore you anymore.

    But if you're going to build it out of transistors, this might help.
    Various Transistor Throttles
    http://home.cogeco.ca/~rpaisley4/Throttles.html

    regards,
    DT

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