Connect with us

Need help for 12F675

Discussion in 'Microcontrollers, Programming and IoT' started by gihanasanka, Aug 14, 2012.

  1. gihanasanka

    gihanasanka

    22
    0
    Aug 14, 2012
    Dear All

    I wrote small programe for 12f675 on assembly. it work. i got 5out put from it. But i need get 5putput with "RC" speed control,

    Hear is my code . Please help me ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !

    https://www.electronicspoint.com/images/smilies/mad.gif


    list p=12f675 ; list directive to define processor
    #include <p12f675.inc> ; processor specific variable definitions
    __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_ON
    ERRORLEVEL -302
    CBLOCK 0x020
    Delay: 1 ; contor delay 100uS
    Delay1: 1 ; contor delay 10mS
    Delay2: 1 ; contor delay 1S
    TEMP: 1 ; contor flash
    ENDC
    BANK0 MACRO ; MACRO DEFINITIONS ___ Selects register bank 0
    BCF STATUS,RP0 ; clear bank select bits
    ENDM
    BANK1 MACRO ; Selects register bank 1
    BSF STATUS,RP0 ;
    ENDM
    DISABLE_IRQ MACRO ; disable global irq
    LOCAL STOP_INT
    START_INT
    BSF INTCON,GIE ; Enable global interrupt
    BTFSS INTCON,GIE ; check if disabled
    GOTO START_INT ; nope, try again
    ENDM
    ORG 0x000 ; processor reset vector
    goto MAIN ; go to beginning of program
    ORG 0x004 ; interrupt vector location
    RETFIE ; return from interrupt
    ORG 0x010; MAIN ROUTINE START HERE
    MAIN:
    Init_Prog:
    BANK1 ; int osc calibration
    call 0x3FF ; get the calibration value
    movwf OSCCAL
    BANK0
    DISABLE_IRQ ; disable irqs / dezactivare intreruperi
    call Init_Ports ; ports init / initializare portur
    Prog_Loop:
    BANK0

    MOVLW D'8
    MOVWF TEMP
    SYS_1_1
    MOVLW B'00000001'
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00000010'
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00000100'
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00010000'
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00100000'
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00010000'
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00000100'
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00000010'
    MOVWF GPIO
    CALL DELAY
    DECFSZ TEMP,1
    GOTO SYS_1_1


    goto Prog_Loop
    ;;-------------------------------------
    movlw 500
    movwf Delay
    DELAY
    decfsz Delay,f
    goto DELAY
    decfsz Delay1,f
    goto DELAY

    ;---------------------
    Init_Ports:
    BANK0 ; Bank 0
    clrf GPIO ; 1)Status of pins: GPIO (GPIO=0 <ViL, =1 >ViH)
    movlw B'00111111' ; 2)Comparator configuration
    movwf CMCON ; Set GP<2:0> digital IO (comparator Off)
    BANK1 ; Bank 1
    bcf OPTION_REG,5 ; 3)TMR0 clock source select: Internal instruction cycle clock (CLKOUT)
    bsf OPTION_REG,7 ; 4)GPIO pull-ups: is disabled
    clrf WPU ; 5)Clear weak pull-up register
    clrf IOC ; 6)Clear Interrupt-on-change register

    movlw B'00000000' ; pins 3 & 4 are inputs and pins 2,5,6,7 are outputs
    movwf TRISIO

    ; clrf ANSEL ; 8)* xxxx ANS<3..0> =0 digital I/O, =1 analog input
    movlw b'00000000' ; pin 3 is analog,
    movwf ANSEL




    BANK0
    return
    org 3FFh
    retlw 0x9C ;
    ;-----------------------------------------------------------------------------
    END ; directive 'end of program'
    ;-----------------------------------------------------------------------------2:0
     
  2. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    I'm not too keen on ASM.

    Though I don't quite understand your issue

    "i got 5out put from it. But i need get 5putput with "RC" speed control,"

    I interpret this as you have a basic program working with 5 outputs with the pattern moving within the loop. Well done, getting the an output or led flashing can be difficult when you are new to a chip.

    With an RC Speed control. Do you mean Remote Controlled Speed Control such as http://www.edutek.ltd.uk/Circuit_Pages/RC_Speed_Controller.html ?
     
  3. gihanasanka

    gihanasanka

    22
    0
    Aug 14, 2012
    Thanks for reply.
    I meaning RC is resitanta control (10k + 100k preset-serial methad) get variour speed, (adjusting preset and give 0v to 5v to 12f675 pin no2)
     
  4. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    i guess you mean potentiometer?

    you need to you an Analogue / Digital module. The module with the same name in the datasheet chapter 7 in this version of the datasheet http://ww1.microchip.com/downloads/en/devicedoc/41190c.pdf

    by reading the 10 bit value once you have correctly configured the module, you should be able to adjust the time period of the delay to be proportional to the voltage at the AD module which would affect the speed of the program.
     
  5. gihanasanka

    gihanasanka

    22
    0
    Aug 14, 2012
    Thanks for reply.

    I think you got miss undrestand.
    Hear i am attached diagrame for above matter.
    Now i need a get 5output from above cc't with that 100k preset. (There are 4output, i tested and that's ok)
    Please give me get 5out.
    Thanks
     

    Attached Files:

  6. CocaCola

    CocaCola

    3,635
    4
    Apr 7, 2012
    As always read the chips datasheet...

    GPIO3 aka pin 4 is INPUT ONLY (when not MCLR)

    Move your variable input to GPIO3 and use GPIO0, GPIO1, GPIO2, GPIO4, GPIO5 as the outputs...

    Or multiplex using 4 outputs if you are only driving LEDs...
     
    Last edited: Aug 15, 2012
  7. hexreader

    hexreader

    105
    19
    Apr 21, 2011
    PIC12F675 GP3 is DIGITAL input only (if not used as reset pin). It is impossible to have one analogue input and 5 digital outputs with this PIC.

    Also, your circuit for analogue input will not work. It will always show as "high" whatever your potentiometer setting.

    What you want is impossible with this PIC

    ... and as usual I agree with CocaCola about reading the datasheet (but disagree about analogue input on GP3)
     
    Last edited: Aug 15, 2012
  8. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    is this output wired differently to the rest? If the diagram is accurate the rest of the pins are floating!

    My limited understanding of hardware I think you are trying to drive a pin that has been set up in hardware to be an input. I see know other reason to drive a line with a pot.
     
  9. CocaCola

    CocaCola

    3,635
    4
    Apr 7, 2012
    To use the pins built in ADC to obtain an externally controllable variable... In this case I believe he wants to use it as a speed control in the delay routine...
     
  10. CocaCola

    CocaCola

    3,635
    4
    Apr 7, 2012
    Yep you beat me to it, went back to correct/edit that and saw your post...

    If you want the 5 outputs you can use Charlieplexing to control 6 LEDs with 3 outputs...
     
  11. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    I think your spot on there.
     
  12. gihanasanka

    gihanasanka

    22
    0
    Aug 14, 2012
    THANKS

    NOW I UNDERSTOOD. THEREFORE CAN I GET 4OUT WITH CONTROL AS ME DR OWING?
    WHICH LINE I HAVE TO CHANGE IN MY PROGRAM...
    Thanks
    ---------------------------------------------------------------

    list p=12f675 ; list directive to define processor
    #include <p12f675.inc> ; processor specific variable definitions
    __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_ON
    ERRORLEVEL -302
    CBLOCK 0x020
    Delay: 1 ; contor delay 100uS
    Delay1: 1 ; contor delay 10mS
    Delay2: 1 ; contor delay 1S
    TEMP: 1 ; contor flash
    ENDC
    BANK0 MACRO MACRO DEFINITIONS ___ Selects register bank 0
    BCF STATUS,RP0 ; clear bank select bits
    ENDM
    BANK1 MACRO ; Selects register bank 1
    BSF STATUS,RP0 ;
    ENDM
    DISABLE_IRQ MACRO ; disable global irq
    LOCAL STOP_INT
    START_INT
    BSF INTCON,GIE ; Enable global interrupt
    BTFSS INTCON,GIE ; check if disabled
    GOTO START_INT ; nope, try again
    ENDM
    ORG 0x000 ; processor reset vector
    goto MAIN ; go to beginning of program
    ORG 0x004 ; interrupt vector location
    RETFIE ; return from interrupt
    ORG 0x010; MAIN ROUTINE START HERE
    MAIN:
    Init_Prog:
    BANK1 ; int osc calibration
    call 0x3FF ; get the calibration value
    movwf OSCCAL
    BANK0
    DISABLE_IRQ ; disable irqs / dezactivare intreruperi
    call Init_Ports ; ports init / initializare portur
    Prog_Loop:
    BANK0
     
  13. CocaCola

    CocaCola

    3,635
    4
    Apr 7, 2012
    I'm not quite sure what you are asking...
     
  14. gihanasanka

    gihanasanka

    22
    0
    Aug 14, 2012
    Sorry for above

    any way Can you give me complete program in assembly for pic 12f675 with 4out put and speed controlling by 10k preset as my earlier diagrammed.

    Thanks
     
    Last edited: Aug 21, 2012
  15. CocaCola

    CocaCola

    3,635
    4
    Apr 7, 2012
    Sorry I don't program in assembly...
     
  16. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    mate, you were almost there don't give up and expect the work done for you, its just a bit of reading the datasheet, and bit masking will solve the issues.

    GP3 is input only, I can't find on my copy of the datasheet what external pin this lines up to.

    GP3 is not an analogue input unfortunately as hexreader said. You need to use GP0, GP1, GP2, or GP4 as the input. Choose one of these to connect the POT input to control the speed.

    The only solution right now I can think of, without using a different variant of the PIC that will suit your needs is with 3 AND gates and 2 NOT Gates.
    LED0:GP1
    LED1:GP2
    LED2:GP4&NOT GP5
    LED3:GP5 &NOT GP4
    LED4:GP4& GP5

    Below I will try to attempt to help for the logic. This assumes that the code you orginally posted works. And there is no guarantee that my hack on it will work, it just is my way of communicating to you there is solution to the logic problems as I believe there is a language barrier here.

    Note: I haven't got the patients to include the logic using the Analogue module. Though all you need to do is to read the analogue value and make it the value you are pushing into your delay routine. this will allow you to turn the POT the AN0 10 bit value will change proportionally.

    GP0:AN):AnalogueIn
    GP1:eek:ut:LED0
    GP2:eek:ut:LED1
    GP3:N/A
    GP4&NOTGP5:eek:ut:LED2
    GP5&NOTGP4:eek:ut:LED3
    GP4 & GP5: out: LED4

    list p=12f675 ; list directive to define processor
    #include <p12f675.inc> ; processor specific variable definitions
    __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_ON
    ERRORLEVEL -302
    CBLOCK 0x020
    Delay: 1 ; contor delay 100uS
    Delay1: 1 ; contor delay 10mS
    Delay2: 1 ; contor delay 1S
    TEMP: 1 ; contor flash
    ENDC
    BANK0 MACRO ; MACRO DEFINITIONS ___ Selects register bank 0
    BCF STATUS,RP0 ; clear bank select bits
    ENDM
    BANK1 MACRO ; Selects register bank 1
    BSF STATUS,RP0 ;
    ENDM
    DISABLE_IRQ MACRO ; disable global irq
    LOCAL STOP_INT
    START_INT
    BSF INTCON,GIE ; Enable global interrupt
    BTFSS INTCON,GIE ; check if disabled
    GOTO START_INT ; nope, try again
    ENDM
    ORG 0x000 ; processor reset vector
    goto MAIN ; go to beginning of program
    ORG 0x004 ; interrupt vector location
    RETFIE ; return from interrupt
    ORG 0x010; MAIN ROUTINE START HERE
    MAIN:
    Init_Prog:
    BANK1 ; int osc calibration
    call 0x3FF ; get the calibration value
    movwf OSCCAL
    BANK0
    DISABLE_IRQ ; disable irqs / dezactivare intreruperi
    call Init_Ports ; ports init / initializare portur
    Prog_Loop:
    BANK0

    MOVLW D'8
    MOVWF TEMP
    SYS_1_1
    MOVLW B'00000010' ;GP1
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00000100' ;GP2
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00010000' ; GP4 - note we skiped the GP3
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00100000' ; GP5
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00110000' ; GP4 & GP5 if you wire up and AND Gate you will have another led when GP4 and GP5 are both high
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00100000' ; GP5
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00010000' ; GP4
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00000100' ; GP2
    MOVWF GPIO
    CALL DELAY
    MOVLW B'00000010' ; GP1
    MOVWF GPIO
    CALL DELAY
    DECFSZ TEMP,1
    GOTO SYS_1_1


    goto Prog_Loop
    ;;-------------------------------------
    movlw 500
    movwf Delay
    DELAY
    decfsz Delay,f
    goto DELAY
    decfsz Delay1,f
    goto DELAY

    ;---------------------
    Init_Ports:
    BANK0 ; Bank 0
    clrf GPIO ; 1)Status of pins: GPIO (GPIO=0 <ViL, =1 >ViH)
    movlw B'00111111' ; 2)Comparator configuration
    movwf CMCON ; Set GP<2:0> digital IO (comparator Off)
    BANK1 ; Bank 1
    bcf OPTION_REG,5 ; 3)TMR0 clock source select: Internal instruction cycle clock (CLKOUT)
    bsf OPTION_REG,7 ; 4)GPIO pull-ups: is disabled
    clrf WPU ; 5)Clear weak pull-up register
    clrf IOC ; 6)Clear Interrupt-on-change register

    movlw B'00000000' ; pins 3 & 4 are inputs and pins 2,5,6,7 are outputs
    movwf TRISIO

    ; clrf ANSEL ; 8)* xxxx ANS<3..0> =0 digital I/O, =1 analog input
    movlw b'00001001' ; pin GP3 is NA so input by default and GP0/AN0 is analoge in,
    movwf ANSEL




    BANK0
    return
    org 3FFh
    retlw 0x9C ;
    ;-----------------------------------------------------------------------------
    END ; directive 'end of program'
    ;-----------------------------------------------------------------------------2:0
     
    Last edited: Aug 22, 2012
  17. CocaCola

    CocaCola

    3,635
    4
    Apr 7, 2012
    If this is only driving LEDs as I stated previous use Charlieplexing, and take advantage of the tri-states of the pins...

    GPIO.0 Analog Input, use this to read POT value

    GPIO.1 Charlieplex 0
    GPIO.2 Charlieplex 1
    GPIO.4 Charlieplex 2

    GPIO.5 Not used, could be used to expand the Charlieplex array to control up to 12 LEDs

    Control over 6 LEDs with 3 pins...

    [​IMG]

    When GPIO.1 =1 and GPIO.2 =0 and GPIO.4 = INPUT Then LED.1 on
    When GPIO.1 =0 and GPIO.2 =1 and GPIO.4 = INPUT Then LED 2 on
    When GPIO.2 =1 and GPIO.4 =0 and GPIO.1 = INPUT Then LED.3 on
    When GPIO.2 =0 and GPIO.4 =1 and GPIO.1 = INPUT Then LED.4 on

    Ignore the following if you only need 4 LEDs...

    When GPIO.1 =0 and GPIO.4 =1 and GPIO.2 = INPUT Then LED.5 on
    When GPIO.1 =1 and GPIO.4 =0 and GPIO.2 = INPUT Then LED.6 on
     

    Attached Files:

  18. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    Thanks CocaCola

    I'm enlightened with that handy explanation in Charlieplexing. Much better then my solution using gates.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-