selecting pic pins

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
SimonT
Posts: 91
Joined: 04 May 2009 12:45

selecting pic pins

#1 Post by SimonT » 18 Jul 2009 16:32

Ok so I have written my program. but I want to make sure I'm linking software to harware proporly.

Basically what do I call each pin for example the PWM output or the ADC input (better known as AN I beleive)

if I'm using the AN0 channel on the pic do I call this AN1 or AN0 in the software ?

I'm planning on using a 16F88

norbie
Posts: 160
Joined: 06 May 2006 22:40
Location: Vista, California

#2 Post by norbie » 18 Jul 2009 19:09

Hi SimonT,
as I understand your question, you are trying to find out what you should call the pins in your program.

The naming convention is entirely up to you.
For example:
If you would like to switch a LED on that you call Power On Indicator, you can use some descriptive short name.

Declare the pin first as an Symbol i.e.

Symbol pwr_on = PORTB.5
Symbol active = 1
Symbol inactive = 0

Like the above.

Now you can use the Symbol pwr_on in your program like this:

Code: Select all

' Condition checking
If power_flag = True then       ' If the power_flag was set elsewhere
  pwr_on = active                   ' Switch PORTB.5 (pwr_on) high
    Else                                  ' if the above is not true
 pwr_on = inactive                 ' keep the pwr_on (PORTB.5) low
End If

Key is, to assign or declare the MCU pins that are defined in the compilers library to whatever name you like.

In case of Analog channel input or PWM output the same rules apply.
You can call AN1 for Example Batt_Volt using the same procedure as above.

i.e.
Symbol Batt_Volt = PORT.whatever it is
Batt_Value = Read_ADC(Batt_Volt)

Just keep in mind that the TRIS register have to be programmed for your purpose.

Cheers,
Cheers,
Norbert

You don't need to know the answer, you just need to know where to find it!

SimonT
Posts: 91
Joined: 04 May 2009 12:45

#3 Post by SimonT » 18 Jul 2009 19:14

I was mainly refering to peripherals/devices, I have compiled my program and it builds ok so heres hoping. Below is my program for your amusement...

Code: Select all


program MPPT

include

dim Duty, Ih, Il as byte

main:

  Duty  = 150                 ' initial value for current_duty

  PWM1_init(5000)                      ' start PWM1 @ 5 KHz

  PWM1_Set_Duty(duty)        ' Set current duty for PWM1
  
  PWM1_start()

 run:

   inc (Duty)
 
   Ih = ADC_read(1)
   
   Delay_ms 100
   
   duty = (duty - 2)
   
   Il = ADC_read(1)



    if (Ih > Il) then
      Inc(duty)                 ' increment Duty cycle
    end if
    
    PWM1_Set_Duty(Duty)
    
  goto run

end.

norbie
Posts: 160
Joined: 06 May 2006 22:40
Location: Vista, California

#4 Post by norbie » 18 Jul 2009 19:38

Hi again,
great if it works!
However, I am somewhat lost in regards to peripherals / devices?

Peripherals depend on what pin they are connected to. From there you'll use the PORT.number where the peripheral/device is connected to.
The PORT.pin can be Symbolized and any name given according to the above scheme.
The peripherals available within the MicroChip are predefined by the compiler library. In almost all cases the names used are identical to the MicroChip Spec. Sheet and depend on the Chip used.
In your program you are already using variable names and library names/functions.

Forgive me, but probably didn't understand the question completely.

Cheers,
Cheers,
Norbert

You don't need to know the answer, you just need to know where to find it!

SimonT
Posts: 91
Joined: 04 May 2009 12:45

#5 Post by SimonT » 19 Jul 2009 11:07

Hi Norbie

thanks for your reply, no I'm not too sure of your question, Although slightly ambitious this is my first program ever that i write myself and actually compile successfully.

I might be able to comprehend how the progra,m works and be able to work out the electronics i need but i'm not too good at getting the program to relate to the physical hardware.

for this reason I am uncertain how to get things linked up.

I just recompiled my program using PWM0 instead of PWM1 and it won't compile so I'll use PWM1 so at this point is PWM1 the channel "0" or "1" on the pysical pic ?

but ADC0 works rather than ADC1 so I'm confused now

cymb
Posts: 464
Joined: 30 Nov 2008 01:19
Location: indiana usa

not sure what you need so,,,

#6 Post by cymb » 19 Jul 2009 23:39

i'll just add a small thought

look at the data sheet, i/o ports section

see how many pins the ports have

lets say port b has 8 bits or pins
they will be numbered 0 to 7 and will be connected to the pic hardware at pins???? thias can be different for various pics

sometime they are all in a row, nice and neat,, othertimes they are "scattered"!

pick the port pin you need , 0 thru 7 , then connect to the physical pin, probably, usually a different number

have fun

tom
not an appliance operator

Post Reply

Return to “mikroBasic PRO for PIC General”