+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Junior Member level 2
    Points: 711, Level: 5

    Join Date
    Jul 2012
    Posts
    21
    Helped
    0 / 0
    Points
    711
    Level
    5

    Problem of Driving Pin High in 16F1828

    Hi,

    I in the middle of porting the MCU from 16F685 to 16F1828. Before transfer the old code to 18F1828, I've tried to run the MCU with the simple test program.
    I'm using PICKit Eval board as to test the program. After program and run, found out the output pin of RC0 cannot drive the LED which only give about 1V output.

    with the same code, change of config, I've run in 16F690 and there is no problem and LED able to be light up. Anything config that I miss out or wrong which I may overlook.

    Below is original code of the 16F1828:-




    #include
    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF

    cblock 0x20
    Delay1 ;Define two file registers for the
    Delay2 ; delay loop endc

    org 0
    Start
    banksel TRISC
    bcf TRISC,0 ; make IO Pin B.0 an output


    movlw b'01101010' ;set osc
    banksel OSCCON
    movwf OSCCON ;configure OSCCON register


    MainLoop
    bsf PORTC,0 ; turn on LED C0

    OndelayLoop
    decfsz Delay1,f ; Waste time.
    goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
    decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
    goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec. ; call it a two-tenths of a second.

    bcf PORTC,0 ; Turn off LED C0

    OffDelayLoop
    decfsz Delay1,f ; same delay as above goto OffDelayLoop
    decfsz Delay2,f
    goto OffDelayLoop
    goto MainLoop ; Do it again...

    end

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 5
    Points: 20,490, Level: 34
    Achievements:
    7 years registered

    Join Date
    May 2009
    Location
    Prime Meridian
    Posts
    3,056
    Helped
    892 / 892
    Points
    20,490
    Level
    34

    Re: Problem of Driving Pin High in 16F1828

    Hi,

    With these latest chips multifunction pins its easy to get things wrong when configuring them, however I think for PortC.0 its ok as you have done it, though it might be good practice to turn off the Analogue function in case you use any other Portc pins as Digital inputs.

    Think your problem is that the ON delay is just 1ms and the OFF time 197ms, using the 4mhz osc you specify in Osccon - see Sim pictures.

    Usually use this calculator for assembly delays.http://www.golovchenko.org/cgi-bin/delay


    Edit, your code would not build because you missed off the ENDC to the CBLOCK directive

    Code:
    	cblock 0x20
    	Delay1 ;Define two file registers for the
    	Delay2 ; delay loop endc
    	endc



    •   AltAdvertisment

        
       

  3. #3
    Junior Member level 2
    Points: 711, Level: 5

    Join Date
    Jul 2012
    Posts
    21
    Helped
    0 / 0
    Points
    711
    Level
    5

    Re: Problem of Driving Pin High in 16F1828

    Hi,

    Thanks. I've manage to trigger the output as required. Below is the modified code.



    banksel OSCCON
    movlw b'01101010' ;set osc
    movwf OSCCON ;configure OSCCON register

    BANKSEL PORTC
    CLRF PORTC ;Init PORTC
    BANKSEL LATC ;Data Latch
    CLRF LATC
    BANKSEL ANSELC
    CLRF ANSELC ;Make RC<5:0> digital
    BANKSEL TRISB
    MOVLW b'00110000' ;Set RC<5:4> as inputs
    ;and RC<3:0> as outputs
    MOVWF TRISC

    banksel STATUS ;Back to Back 0

    MainLoop

    I've not look into detailed as I just want to test on the run. By the way, what compiler are you using as it's look new to me as I've never saw the tools with debug for the timer?

    However, is that better way of switch back to bank0 when using "banksel" command?
    Also, is that any way or good idea of making makro of the bank selection?

    Thanks....
    Kah Joo



    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 76,044, Level: 67
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,439
    Helped
    4143 / 4143
    Points
    76,044
    Level
    67

    Re: Problem of Driving Pin High in 16F1828

    That looks like the standard MPLAB stopwatch window to me.

    'banksel' works in all cases but if you really have to optimize your code, there is a new instruction 'movlb x' which will directly select bank 'x' in a single step. I think MPLAB and MPLABX will automatically substitute movlb when you use the banksel directives, but obvioulsy only on the newer devices supporting that instruction, otherwise it sets/resets bits in the STATUS register instead.

    Heed wp100's caution about multi-function pins, as you migrate to devices with more on-board peripherals it become important to select which the pin is internally connected to.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  5. #5
    Advanced Member level 5
    Points: 20,490, Level: 34
    Achievements:
    7 years registered

    Join Date
    May 2009
    Location
    Prime Meridian
    Posts
    3,056
    Helped
    892 / 892
    Points
    20,490
    Level
    34

    Re: Problem of Driving Pin High in 16F1828

    Quote Originally Posted by kahjoo View Post
    Hi,

    Thanks. I've manage to trigger the output as required. Below is the modified code.






    I've not look into detailed as I just want to test on the run. By the way, what compiler are you using as it's look new to me as I've never saw the tools with debug for the timer?

    However, is that better way of switch back to bank0 when using "banksel" command?
    Also, is that any way or good idea of making makro of the bank selection?

    Thanks....
    Kah Joo

    Hi,

    You can use the movlb D'1' ; bank1 as Brian mentions but if you are using various 16Fs it might be more compatible to use the banksel directive.
    To return to bank 0 just use ' banksel 0 ' - bansel 1 etc does not work, you must specify a register.

    The pictures shown are of the stopwatch used in MPlabs SIM.

    Build your code, goto Debugger, select tool, MPLABSIM then you can either RUN or Single Step though your code.

    However for a long delay you really want to 'run' over it, so on your line of code Right click and Set a Breakpoint before and after the delay.

    You then Start the STOPWATCH and set it to 4mhz , run to the first breakpoint, zero the stopwatch, Run to the second breakpoint to find your delay time.

    You can do many other things using the Watch Windows to see how you code changes the system and user registers etc etc



    •   AltAdvertisment

        
       

  6. #6
    Junior Member level 2
    Points: 711, Level: 5

    Join Date
    Jul 2012
    Posts
    21
    Helped
    0 / 0
    Points
    711
    Level
    5

    Re: Problem of Driving Pin High in 16F1828

    Hi,

    Thanks for the information. Will try it soon. Thanks again.

    Kah Joo



--[[ ]]--