Selecting peripheral pins

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
reip
Posts: 3
Joined: 30 Sep 2020 16:08

Selecting peripheral pins

#1 Post by reip » 01 Oct 2020 14:11

Hello from a mikroC newbie!

What is the right way to map pins for PWM and UART when using according mikroC PRO for PIC32 library functions? For example, I am using a PIC32MX250F128B microcontroller and here I have a simple code for just trying PWM with this MCU:

Code: Select all

unsigned int pwm_period;

void init_MCU()
{
  JTAGEN_bit = 0;

  ANSELA = 0;
  ANSELB = 0;

  TRISA = 0;
  TRISB = 0;

  LATA = 0;
  LATB = 0;

  Unlock_IOLOCK();

     PPS_Mapping( _RPB3, _OUTPUT, _OC1 );

  Lock_IOLOCK();
}

void main() {
      init_MCU();
      
      pwm_period = PWM_Init(10000, 1, 1, 2);
      
      PWM_Start(1);
      
      PWM_Set_Duty(pwm_period/2,  1);
}
I am using PWM channel 1 which, as I understand, means OC1 and with OC1 it should be possible to use the pin B3. The code compiles but when I load it to the MCU then it doesn't work, nothing happens. I think that I'm doing something wrong or missing something but can somebody tell me what exactly?

And the same thing with UART. Before I use UARTx_Init() and UARTx_Write() or UARTx_Read(), how do I determine which pins to use as TX and RX?

Thanks for help!

hexreader
Posts: 1786
Joined: 27 Jun 2010 12:07
Location: England

Re: Selecting peripheral pins

#2 Post by hexreader » 01 Oct 2020 16:15

Nothing wrong with your code, as far as I can tell.

My guess is that there is a problem with your Configuration bit settings, or maybe your hardware.

Zip up whole project folder and attach (like I have below) so we can see more information. Tell us what oscillator you use.

I assume that you use an oscilloscope to check for 10KHz on RB3?

Try the attached simple project to check hardware. If that works - hardware is probably good, other than maybe crystal, which this project does not use.
Attachments
pintest.zip
(95.85 KiB) Downloaded 65 times
Start every day with a smile...... (get it over with) :)

reip
Posts: 3
Joined: 30 Sep 2020 16:08

Re: Selecting peripheral pins

#3 Post by reip » 02 Oct 2020 10:14

Thanks for the file! I tried it and didn't see anything happening...
The hardware should work, some programs have run nicely on it. But yes, maybe something is wrong with the configuration of that particular project. I added the whole project, maybe you can find some mistakes in settings. I am using internal oscillator.
Attachments
PWMproov.zip
(146.55 KiB) Downloaded 43 times

Post Reply

Return to “mikroC PRO for PIC32 General”