Recommendations - Model Train Controller


Closed Thread
Results 1 to 40 of 102

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    No secret, Malc ...

    PWM freq too low.
    ( may be also a poor quality motor too ... but you can't choose which will be used.)

    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    No secret, Malc ...

    PWM freq too low.
    Alain
    The max setting I can use seems to be 190 for freqency, 255 for resolution, with an OSC value of 20

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


    Did you find this post helpful? Yes | No

    Default I have a headacke !

    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

    Code:
    @ __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
    Here's hoping someone can point e in the right direction

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


    Did you find this post helpful? Yes | No

    Default Seems I'm the only one posting :)

    Ok I think I now understand the settings for ANSEL. Reading the datasheet again
    ANSEL — ANALOG SELECT REGISTER (ADRESS: 91h) (PIC16F676 ONLY)

    ANS7 ANS6 ANS5 ANS4 ANS3 ANS2 ANS1 ANS0
    bit 7 bit 0
    bit 7-0: ANS<7:0>: Analog Select between analog or digital function on pins AN<7:0>, respectively.
    1 = Analog input. Pin is assigned as analog input.(1)
    0 = Digital I/O. Pin is assigned to port or special function.
    So if I wanted all analogue I set ANSEL to 11111111 - all digital 00000000

    Ergo to set AN0, AN1, AN2 and AN4 Ansel should = 00010111, which is exactly what Darrel suggested. However when compiled with this setting the 4th output still runs at full speed with no control.

    Could it be that the issue is with the declaration of the array - as it has [3] and I would assume that there are 4 channels so maybe this should be [4] ??

    Quote Originally Posted by malc-c View Post

    Could it be that the issue is with the declaration of the array - as it has [3] and I would assume that there are 4 channels so maybe this should be [4] ??
    Looked like that was teh cause - I now have 4 working channels... just need to resolve the issue of the PIC locking on at full throttle and I'm done !
    Last edited by malc-c; - 16th February 2007 at 20:47.

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


    Did you find this post helpful? Yes | No

    Default

    Boy. Try to get some sleep, and people start talking to themselves.

    Looks like the guy you were talking to, helped figure a couple things out though.

    Good catch on the array size. Didn't see that.

    Heard the video. That's just nasty sounding.
    Is it any better yet after the changes?

    I know you were told to change SPWM_RES to 255, but it really should be 256 for 8-bit resolution. Maybe the cause of the "PIC locking on at full throttle". I'll play with it here too and see.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    After further playing.

    I can't make it "Lock".

    Tried all 4 channels, tried 255/256 RES.

    Incidently, 255 does work better. It's not the way I thought I wrote it. But...

    That way 0 is always off, and 255 is always on.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    If using an LED its hard to make it lock. I think its either related to the power supply I'm using, or some other factor within the circuit as it does it on several loco's. I have a 0.1uf spread accros the power pins of the PIC, and power rails in a bid to decouple the supply. I've also tried changing the 1K base resistor between the NPn and PIC output as I though that the driver circuit may be drawing more than the 25ma the port can take, but that made no difference

    Is the PWM outout a square wave, sawtooth or just spikes that are increased in frequency? I would like to stick with PWM as there is less heat to dissapate in the circuit and it provides far better slow starts than varible voltage type controllers. Maybe I should look at using a PIC with hardware PWM, like the 16F690 ??

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