Working with a dsPic33fj128GP804

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
richcj10
Posts: 29
Joined: 15 Aug 2012 13:51

Working with a dsPic33fj128GP804

#1 Post by richcj10 » 15 Aug 2012 13:58

Code:
Pic clocked at 40mhz

Code: Select all


program Get to work

' Declarations section 
dim current_duty, old_duty, current_duty1, old_duty1 as word
    pwm_period1, pwm_period2 as word
    
dim i as word
dim count as word
dim prevcount as word
dim prevcount2 as word
dim L as bit
dim Value as integer

sub procedure Initsubsys()
TRISC.7=0  ' as input for uart1 read
TRISC.6=1 '  as output for uart1 write
TRISB.10=1  ' as output for PWM
TRISB.11=1 '  as output for PWM

Unlock_IOLOCK()
  PPS_Mapping(11, _OUTPUT, _OC2)     ' Sets RPx pin 10 to be PWM
  PPS_Mapping(10, _OUTPUT, _OC1)     ' Sets RPx pin 11 to be PWM
  PPS_Mapping(22, _OUTPUT, _U1TX) 'mapping RPx pin 22 as uart1 output
  PPS_Mapping(23, _INPUT, _U1RX) ' mapping RPx pin 23 as uart1 input
Lock_IOLOCK()

  UART1_Init(9600)                        ' Initialize UART module at 9600 bps
  Delay_ms(100)                           ' Wait for UART module to stabilize
  UART1_Write_Text("Starting:")
  PWM_Init(5000 ,  1, 1, 2)
  PWM_Init(10000 , 2, 1, 3)

  PWM_Start(1)
  PWM_Start(2)

  PWM_Set_Duty(0, 1)             ' Set current duty for PWM1
  PWM_Set_Duty(0, 2)             ' Set current duty for PWM2
  UART1_Write_Text("Setup Done:")
end sub

sub procedure InitSensors()

  PortB.8 = NOT PortB.8
  Delay_ms(150)
  PortB.8 = NOT PortB.8
  Delay_ms(150)
  PortB.8 = NOT PortB.8
  Delay_ms(150)
  PortB.8 = NOT PortB.8
  Delay_ms(150)
  PortB.8 = NOT PortB.8
  Delay_ms(150)
  PortB.8 = NOT PortB.8
  Delay_ms(150)
  PortB.8 = NOT PortB.8
  Delay_ms(150)
  PortB.8 = NOT PortB.8

end sub

main:
  Initsubsys()
  TRISB.8 = 0
  SetBit(PORTB, 8)
  UART1_Write_Text("Menu? ")
  'Delay_ms(1000)
  if ( UART1_Data_Ready() = 1) then
    UART1_Write_Text("1) T/C ")
    UART1_Write_Text("2) NOx / OX ")
    UART1_Write_Text("3) Current ")
    UART1_Write_Text("3) Reset ")
    UART1_Write_Text("5) About")
  end if
  InitSensors()
  while (TRUE)             ' endless loop
  count = count + 1
  'UART1_Write(count)
  Delay_ms(1)
  if (count = prevcount + 250) then
    prevcount = count
    PortB.8 = NOT PortB.8
   end if
  if (count = prevcount2 + 50) then
    prevcount2 = count
    if Value <= 300 then
       UART1_Write_Text(" PWM: ")
       UART1_Write(Value)
      PWM_Set_Duty(Value, 1)
      PWM_Set_Duty(Value, 2)
    else
      Value = 0
    end if
   end if
  wend
end.
my questions:
1) I had serial working then it just stopped... any ideas?
2) This Pic has 4 PWM's. I had one working(OC1) but when trying to get both working they both stopped functioning... any Ideas?
3) I am working on a "scheduler" for programs on the pic...It is pretty terrible. Any ideas on how to improve?

Thanks for any help!

Rick

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Working with a dsPic33fj128GP804

#2 Post by dejan.odabasic » 22 Aug 2012 17:02

Hello,

I believe that we had email correspondence regarding this issue.

Best regards.

richcj10
Posts: 29
Joined: 15 Aug 2012 13:51

Re: Working with a dsPic33fj128GP804

#3 Post by richcj10 » 22 Aug 2012 19:16

We did... I didn't think it posted.... sorry
FTR: it was the pin mapping config bits in edit program settings

MrB
Posts: 30
Joined: 09 Aug 2012 06:15
Location: Perth Western Australia

Re: Working with a dsPic33fj128GP804

#4 Post by MrB » 23 Aug 2012 06:32

richcj10 wrote:FTR: it was the pin mapping config bits in edit program settings
Thumbs up for posting this.
It is sad that so many solutions to problems are hidden from public view in PM's and emails, where they will not help other coders that may hit similar problems in future.
Image
EasyMx PRO v7 for STM32 | F407VG MCU card | STM32F4-Discovery | FriendlyARM mini2440

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Working with a dsPic33fj128GP804

#5 Post by dejan.odabasic » 23 Aug 2012 15:16

Hello,

I just want to add an extra explanation for users that experienced similar problems.
When you call function PPS_Mapping() you are basically doing the following:

Code: Select all

Unlock_IOLOCK()
  PPS_Mapping_NoLock(..., ..., ...) 
Lock_IOLOCK()
and when you write the following:

Code: Select all

Unlock_IOLOCK()
  PPS_Mapping(..., ..., ...)
  PPS_Mapping(..., ..., ...)
  PPS_Mapping(..., ..., ...)
Lock_IOLOCK()
you actually did

Code: Select all

Unlock_IOLOCK()
  Unlock_IOLOCK()
    PPS_Mapping_NoLock(..., ..., ...)
  Lock_IOLOCK()
  Unlock_IOLOCK()
    PPS_Mapping_NoLock(..., ..., ...)
  Lock_IOLOCK()
  Unlock_IOLOCK()
    PPS_Mapping_NoLock(..., ..., ...)
  Lock_IOLOCK()
Lock_IOLOCK()
This requires that you set in Edit Project window - Allow multiple reconfiguration at Peripheral pin select configuration option

Or if you really need to set it only once at initialization, you should use:

Code: Select all

Unlock_IOLOCK()
  PPS_Mapping_NoLock(..., ..., ...)
  PPS_Mapping_NoLock(..., ..., ...)
  PPS_Mapping_NoLock(..., ..., ...)
Lock_IOLOCK()
Best regards.

richcj10
Posts: 29
Joined: 15 Aug 2012 13:51

Re: Working with a dsPic33fj128GP804

#6 Post by richcj10 » 10 Sep 2012 00:45

Well, if documentation was better than I wouldn't have all these issues.... just saying...

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Working with a dsPic33fj128GP804

#7 Post by dejan.odabasic » 10 Sep 2012 08:04

Hello,

If you have suggestions, how could we improve our documentation, please share them with us.
We would be glad to hear feed back from you.

Best regards.

btltk
Posts: 7
Joined: 17 Nov 2013 16:03

24fj256gb106

#8 Post by btltk » 26 Dec 2013 21:28

Hi,I tried sd card and mikrocontroller communication with SPI but I think I didn't mapping.Because I tried P18f452 it works but not working with Pic24.Mmc_init function is not working.Data output pin of SD card is not working.I tried on the hardware but it didn't work again.
Last edited by btltk on 25 Jan 2014 13:37, edited 1 time in total.

richcj10
Posts: 29
Joined: 15 Aug 2012 13:51

Re: Working with a dsPic33fj128GP804

#9 Post by richcj10 » 26 Dec 2013 22:35

I see you did the PPS_Mapping instead of PPS_Mapping_NoLock.
I think your encountering the same issue I had. use PPS_Mapping_NoLock instead and see if that works.

btltk
Posts: 7
Joined: 17 Nov 2013 16:03

Re: Working with a dsPic33fj128GP804

#10 Post by btltk » 27 Dec 2013 07:05

I tried it but it didn't work.

richcj10
Posts: 29
Joined: 15 Aug 2012 13:51

Re: Working with a dsPic33fj128GP804

#11 Post by richcj10 » 27 Dec 2013 07:38

Let's see all your code. How do you have it hooked up?

btltk
Posts: 7
Joined: 17 Nov 2013 16:03

Re: Working with a dsPic33fj128GP804

#12 Post by btltk » 27 Dec 2013 13:32

Codes Deleted
Last edited by btltk on 25 Jan 2014 13:41, edited 1 time in total.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Working with a dsPic33fj128GP804

#13 Post by filip » 30 Dec 2013 10:26

Hi,

Please, can you verify that the used pins work OK, when toggling them for example ?

Regards,
Filip.

btltk
Posts: 7
Joined: 17 Nov 2013 16:03

Re: Working with a dsPic33fj128GP804

#14 Post by btltk » 01 Jan 2014 21:57

I tried it but leds didn't toggle,continuously light.I also run without adding sd card commands but result didn't change...Have you any idea?

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”