• AVR Freaks

Helpful Replyinline statements in PIC32

Author
avil
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2016/06/16 11:57:50
  • Location: 0
  • Status: offline
2017/02/28 03:33:27 (permalink)
0

inline statements in PIC32

Hi,
       Am trying to port 32x16 RGB Display Driver from adafruit (aurdino ) to pic32 microcontroller. i have ported most of the library but stuck at some point below,the #defined one 
 
 
#define pew asm volatile( \
"ld __tmp_reg__, %a[ptr]+" "\n\t" \
"out %[data] , __tmp_reg__" "\n\t" \
"out %[clk] , %[tick]" "\n\t" \
"out %[clk] , %[tock]" "\n" \
:: [ptr] "e" (ptr), \
[data] "I" (_SFR_IO_ADDR(DATAPORT)), \
[clk] "I" (_SFR_IO_ADDR(SCLKPORT)), \
[tick] "r" (tick), \
[tock] "r" (tock));
 
 
// Loop is unrolled for speed:
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
 
How can i port the above to my pic32mx775f256h controller?Here  __tmp_reg__ is aurdino controller register,DATAPORT is PORTB ,SCLKPORT is PORTF,tick , tock are variables.
 

#define SCLKPORT PORTF
#define DATAPORT PORTB
tock = SCLKPORT;
tick = tock | sclkpin;  /*  sclkpin=LATFbits.LATF0*/
#1
rodims
Super Member
  • Total Posts : 1558
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: inline statements in PIC32 2017/02/28 05:23:35 (permalink)
3 (1)
avil, since this seems to be a duplicate of your post
http://www.microchip.com/forums/m977054.aspx
please "mark" one of them as obsolete by using "edit" and replacing all text with some informative text like "deleted, because duplicate".  After some time two identical posts will create a lot of useless 'noise' in the forum.
post edited by rodims - 2017/02/28 05:24:43
#2
avil
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2016/06/16 11:57:50
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/02/28 06:11:30 (permalink)
0
ok will do it. Thankyou 
#3
NorthGuy
Super Member
  • Total Posts : 6359
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: inline statements in PIC32 2017/02/28 06:45:29 (permalink)
4 (1)
Processors are different. You need to re-write the assembler for PIC32/MIPS.
 
PIC32 has cache, so unrolling may not give you more speed.
#4
Mysil
Super Member
  • Total Posts : 3836
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: inline statements in PIC32 2017/02/28 07:53:43 (permalink)
3 (1)
Hi,
While it is possible to use inline assembly code with XC32 compiler for PIC32MX775,
I think the MX775 may be more than fast enough to do this in C, and without unrolling.
 
Find out what the assembler code fragment is actually supposed to do,
or provide a link to datasheet for the display device.
 
DATAPORT is PORTB, I assume data lines to the display is 8 or 16 lines of I/O port B.
Port B have 16 bits, but is addressed by 32 bit wide SFR register words.
 
Then there is a clock signal connected to pin RF0  ?
I think you may do something like this:
    ptr = 0;
    while ( ptr < sizeof(a))
    {
        LATB = a[ptr];    /* Display data from array to output pins. */
        Nop();            /* Fill in with nop instructions if needed. */
        LATFSET = 0x01;   /* Set a bit in port F latch register to make a clock pulse. */
        Nop();            /* Fill in with nop instructions if needed for signal timing. */
       LATFCLR = _LATF_LATF0_MASK;  /* Clear the tick bit to end the clock pulse. This bit is the same as 2 lines above.*/
        ptr ++;           /* Next byte or 16 bit word. */
    } 

There may be some more trickery needed, you must provide more details about the hardware you are using.
 
Regards,
   Mysil
post edited by Mysil - 2017/02/28 08:01:19
#5
avil
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2016/06/16 11:57:50
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/03/01 23:29:13 (permalink)
0
Hi,
      Thank you all for your reply.Let me explain in detailed about the display
 
Am working on 32x16 RGB display with scan rate of 1/4 .It is a HUB75 module.(Different modules work on different protocol.like hub12 works on SPI and Hub75 works on bit banging with Different input Connections).
 
I found a tutorial ADAfruit 32x16 RGB but works for 1/4 scan rate and with aurdino libraries only.the library is aurdino based and C++ which i am converting to C for pic32
 
http://jaanus.tech-thing....matrixes-with-arduino/
and Code in
https://github.com/zidik/.dMatrix16x32-Alternative
 
The principle is out of 512(32x16 leds )only 128 led can be on at a time ie 4 interleaved rows of of 32 led pixels.scan it fast enough to make as if all 512  leds are on at a time using timer .i have to latch 128 bit data using portB(R1,G1,B!,R2,G2,B2 output lines) and PORTF to (A,B,clk,sclk)pins. A abd B pins control the scan lines.
A B
0 0  row 1,5,9,13 is on
0 1  row 2,6,10,14 is on
1 0  row  3,7,11,15 is on
1 1  row  4,8,12,16 is on
after 128 bit values my clk should go high to low and latch pin high to low while scanning the rows.
 
Now i am trying to  Write code to on single pixel using Same library.I have ported almost all the required code other than the   inline statement.
#define pew asm volatile( \
"ld __tmp_reg__, %a[ptr]+" "\n\t" \
"out %[data] , __tmp_reg__" "\n\t" \
"out %[clk] , %[tick]" "\n\t" \
"out %[clk] , %[tock]" "\n" \
:: [ptr] "e" (ptr), \
[data] "I" (_SFR_IO_ADDR(DATAPORT)), \
[clk] "I" (_SFR_IO_ADDR(SCLKPORT)), \
[tick] "r" (tick), \
[tock] "r" (tock));
 
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
pew pew pew pew pew pew pew pew
 

have attached the library Containg the function UpdateDisplay function in the file RGBCPP.txt  file
If am able to port the above code i will be able to use library for different functionality like implementing image ,scrolll etc .otherwise i need to write library fom scratch to on single led pixel,draw char, draw string ,image etc .
 
 
 
#6
NKurzman
A Guy on the Net
  • Total Posts : 18985
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/03/02 07:53:43 (permalink)
3 (1)
You are missing the point.
That is assembly language for and AVR CPU. It is not C or C++.
The AVR is slower than the PIC32 your are using. You should be able to code it directly.
You need a timer and a time interrupt. You can do you multiplexing in there.



What the hell is a PEW?
#7
Mysil
Super Member
  • Total Posts : 3836
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: inline statements in PIC32 2017/03/02 09:53:52 (permalink)
4.5 (2)
pew is the ugly macro that is defined to transfer one word from his frame buffer in memory to IO port registers..
 
Looking around a little, it seem the hardware OP is trying to interface,
use  6 shift registers in parallel,  R1, G1, B1, R2, G2, B2, 
so the protocol is essentially bitbanging SPI, using a byte array as frame buffer.
 
The hardware seem to use shift registers 8 bit or 16 bit something similar to  74HC595,
and probably may be toggled as fast as PIC32MX is able to toggle  a pin with LATFSET  and LATFCLR.
On PIC32MX, this may be done just as fast in C with optimization 1, as in assembler.
 
   Mysil
#8
avil
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2016/06/16 11:57:50
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/03/03 05:32:42 (permalink)
0
Hi ,
         Thank you for response.It seems i will first try to work on 32x16 rgb module without using  library,just bitbanging.so i googled to write simple code.Am latching 128 bit data ANDing with 64 bit data taken in array called rowx[].example if rowx[0]=0xFFFFFFFFFFFFFFFF the row 1 and 5 of display panel is high .if rowx[1]=0xFFFFFFFFFFFFFFFF then row 2 and 5 of display lits up. its working fine with some fliker. Am having a doubt
 
1)In the function loop(),Am unable to latch data if am using
 PIN_DMD_B1_DATA=(rowx[row] & (temp << (63-i)));
 
But it works fine is replaced with 
PIN_DMD_B1_DATA=!!(rowx[row] & (temp << (63-i)));
 
Simillarly,while scanning rows
PIN_DMD_A =(row & 0x01); 
PIN_DMD_A =(row & 0x01);  
  with 
PIN_DMD_A =!!(row & 0x01); 
PIN_DMD_A =!!(row & 0x01); 
Am not understanding the logic behind  it.
 
 Below is the code as am unable to attach code in separate file 
 
#include <plib.h> 
#include "DM.h"
 
#define PIN_DMD_nOE LATBbits.LATB2
#define PIN_DMD_nOE_DIR TRISBbits.TRISB2
#define PIN_DMD_A LATBbits.LATB3 //PORTBbits.RB3 // 
#define PIN_DMD_A_DIR TRISBbits.TRISB3
#define PIN_DMD_B LATBbits.LATB4 //PORTBbits.RB4 // 
#define PIN_DMD_B_DIR TRISBbits.TRISB4
#define PIN_DMD_C LATBbits.LATB6
#define PIN_DMD_C_DIR TRISBbits.TRISB6
#define PIN_DMD_CLK LATGbits.LATG6 // D13_SCK is SPI Clock if SPI is used
#define PIN_DMD_CLK_DIR TRISGbits.TRISG6
#define PIN_DMD_SCLK LATBbits.LATB5 //PORTBbits.RB5 // D8
#define PIN_DMD_SCLK_DIR TRISBbits.TRISB5
#define PIN_DMD_R1_DATA LATGbits.LATG8 // 
#define PIN_DMD_R1_DIR TRISGbits.TRISG8
#define PIN_DMD_G1_DATA LATFbits.LATF0
#define PIN_DMD_G1_DIR TRISFbits.TRISF0
#define PIN_DMD_B1_DATA LATFbits.LATF1
#define PIN_DMD_B1_DIR TRISFbits.TRISF1
 
#define PIN_DMD_R2_DATA LATBbits.LATB9 /
#define PIN_DMD_R2_DIR TRISBbits.TRISB9
#define PIN_DMD_G2_DATA LATBbits.LATB14
#define PIN_DMD_G2_DIR TRISBbits.TRISB14
#define PIN_DMD_B2_DATA LATGbits.LATG9
#define PIN_DMD_B2_DIR TRISGbits.TRISG9
 
uint64_t  rowx[16];
uint64_t  temp;
int main(void)
{
DM();
int i=0;
          while(1){
                         loop();
                       }
}
 
 
void DM(void)
{
PIN_DMD_A_DIR = OUTPUT;
PIN_DMD_B_DIR = OUTPUT;
PIN_DMD_C_DIR = OUTPUT;
 
PIN_DMD_SCLK_DIR = OUTPUT;
PIN_DMD_CLK_DIR= OUTPUT;
 
PIN_DMD_R1_DIR = OUTPUT;
PIN_DMD_G1_DIR = OUTPUT;
PIN_DMD_B1_DIR = OUTPUT;
 
PIN_DMD_R2_DIR = OUTPUT;
PIN_DMD_G2_DIR = OUTPUT;
PIN_DMD_B2_DIR = OUTPUT;
 
 
 
PIN_DMD_nOE_DIR = OUTPUT;
PIN_DMD_A = LOW;
PIN_DMD_B = LOW;
 
PIN_DMD_SCLK = LOW;
PIN_DMD_R1_DATA = LOW;
PIN_DMD_nOE = HIGH;
row=0;
temp = 0x0000000000000001;
 
rowx[0]=0xFFFFFFFFFFFFFFFFFF;
rowx[1]=0x0000000000000000;
rowx[2]=0x0000000000000000;
rowx[3]=0x0000000000000000;
rowx[4]=0x0000000000000000;
rowx[5]=0x0000000000000000;
rowx[6]=0x0000000000000000;
rowx[7]=0x0000000000000000;
 
}
 
void loop()
{
for(row=0; row<4; row++){
for (i = 0; i <64; i++) {
PIN_DMD_B1_DATA=!!(rowx[row] & (temp << (63-i)));
PIN_DMD_R1_DATA=0;
PIN_DMD_G1_DATA=0;
 
PIN_DMD_R2_DATA=!!(rowx[row+4] & (temp << (63-i))); 
PIN_DMD_G2_DATA=0;
PIN_DMD_B2_DATA=0;
 
PIN_DMD_CLK=1; 
PIN_DMD_CLK =0;
}
 
PIN_DMD_nOE=1;
PIN_DMD_SCLK=1;
PIN_DMD_A =!!(row & 0x01); 
 
PIN_DMD_B =!!(row & 0x02);
 
 
 
PIN_DMD_SCLK=0;
 

}
 
 
 
post edited by avil - 2017/03/03 05:40:16
#9
Mysil
Super Member
  • Total Posts : 3836
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: inline statements in PIC32 2017/03/03 07:05:52 (permalink) ☄ Helpfulby avil 2017/03/04 01:05:41
0
Hi,
The struct expression  LATFbits.LATF1 that is behind PIN_DMD_B1_DATA, expect value 0 or 1.
but the bitwise AND operation:  rowx[row] & (temp << (63-i))
will produce a bit result in any bit as you shift thru the bits of the temp variable.
The double negation !! will then translate any bit set into true = 1, or all bits 0 into false = 0;
 
   Mysil
#10
NorthGuy
Super Member
  • Total Posts : 6359
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: inline statements in PIC32 2017/03/03 07:41:10 (permalink) ☄ Helpfulby avil 2017/03/04 01:05:49
0
You can shift it directly where it wants it. Instead of
 
PIN_DMD_R2_DATA=!!(rowx[row+4] & (temp << (63-i)));

 
you could do
 
PIN_DMD_R2_DATA = rowx[row+4] >> (63-i);

#11
avil
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2016/06/16 11:57:50
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/03/05 13:10:54 (permalink)
0
Hi,
       Thankyou for your reply.Now i want to write a universal function which will enable the particular pixel. Example if i want to enable pixel 0 then fun(0,0) 0r pixel 4of x-axis fun(4,0) etc.its seeems a bit complex.
 
       scenerio is row[0]=0xffffffffffffffffffffffff both row 1 and 5 are on (64 pixels)
                         row[0]=0x00ff00ff00ff00ff   Will enable all pixel of row 5
                         row[0]=0xff00ff00ff00ff00    will enable all pixel of row 1
 
         row 5 bits can be configured as 8 4 2 1 mode but row 1 can be configured as 1 2 4 8 mode and reversed LSB and MSB. Like ex i f i want to enable pixel 3 then, its value in row[0] is  
                               row[0]=0x00ff00ff00ff0004
 
 
simillarly if i want to enable pixel 3 of row 1 then row[0],
                                row[0]=0xff00ff00ff002000
                if i want to enable pixel 5 of row 1 then row[0],
                                  row[0]=0xff00ff00ff000800
 
Can anyone suggest me way to write function to set pixel fun(x,y) where x should map x row and y column.am finding it difficult to draw a character in 32x16 by ANDing 128 bits as discussed in previous  posts 
rowx[0]=0xFFFFFFFFFFFFFFFFFF; //some data
rowx[1]=0x0000000000000000;  //some data
rowx[2]=0x0000000000000000; //some data
rowx[3]=0x0000000000000000;
rowx[4]=0x0000000000000000;
rowx[5]=0x0000000000000000;
rowx[6]=0x0000000000000000;
rowx[7]=0x0000000000000000;
 
}
 

for(row=0; row<4; row++){
for (i = 0; i <64; i++) {
PIN_DMD_B1_DATA=!!(rowx[row] & (temp << (63-i)));
PIN_DMD_R1_DATA=0;
PIN_DMD_G1_DATA=0;
 
PIN_DMD_R2_DATA=!!(rowx[row+4] & (temp << (63-i))); 
PIN_DMD_G2_DATA=0;
PIN_DMD_B2_DATA=0;
}
post edited by avil - 2017/03/05 13:18:18

Attached Image(s)

#12
avil
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2016/06/16 11:57:50
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/03/06 05:05:01 (permalink)
0
HI,
        My 32x16 rgb display panel contains JXI5020 IC(16 constant current led driver) of 24 nos.
  12 lower and 12 upper part of display.74HC138 3-to-8 Decoder to control scanlines A,B,C.
#13
TonyShell
Junior Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2016/05/22 20:51:01
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/05/28 23:31:35 (permalink)
3 (1)
Avil, I have 2 of the 32 x 64 RGB LED matrices and I've already got it working.  I can draw things on the screen and place text and I will be writing more code within the next week or so to do more things, but the basic framework is there and it's working.  I have double-buffering working as well as 8 bits for each color.  Since I have a 32 x 128 display, more frame rate takes up CPU resources, but a 32 x 16 display would easily have a good frame rate, over 60 fps without using a lot of CPU time.  Right now, I'm just bit-banging, but I'm thinking I can drive it with PMP and DMA like I can with an LCC LCD and it will use even less CPU.  If you still need some code for this, please let me know and I'll send it to you.
#14
lloyddean
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2011/07/08 21:42:55
  • Location: Seattle, WA
  • Status: offline
Re: inline statements in PIC32 2017/10/27 12:40:15 (permalink)
0
TonyShell
Avil, I have 2 of the 32 x 64 RGB LED matrices and I've already got it working.  I can draw things on the screen and place text and I will be writing more code within the next week or so to do more things, but the basic framework is there and it's working.  I have double-buffering working as well as 8 bits for each color.  Since I have a 32 x 128 display, more frame rate takes up CPU resources, but a 32 x 16 display would easily have a good frame rate, over 60 fps without using a lot of CPU time.  Right now, I'm just bit-banging, but I'm thinking I can drive it with PMP and DMA like I can with an LCC LCD and it will use even less CPU.  If you still need some code for this, please let me know and I'll send it to you.




Tony, what controller are you using and are you willing to show code from your working project?
#15
TonyShell
Junior Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2016/05/22 20:51:01
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2017/10/27 14:00:17 (permalink) ☄ Helpfulby ctrottier 2018/01/02 07:17:58
4 (2)
lloyddean,
 
  I'm using a PIC32MZ2048EFH144.  I can give you the bit-banging code.  It has some drawing functions as well and will even read a non-encoded BMP image from a Micro SD card (uses the MEBII board).  It should be able to be adapted for a smaller display by changing a few #defines and maybe some other things.  How would you like me to share with you?  I have some trouble posting large amounts of code on this forum, so, if you give me your email address, I could send it.  Just to make sure, your display has the R1, R2, G1, G2, B1, B2, OE, LAT & CLK pins, correct?  I just want to make sure it's the same type of display.  Let me know.
 
Thanks,
Tony
#16
lloyddean
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2011/07/08 21:42:55
  • Location: Seattle, WA
  • Status: offline
Re: inline statements in PIC32 2017/10/27 14:29:00 (permalink)
3 (1)
Hello Tony
 
A friend has shown interest in interfacing a 16x32 matrix RGB display and does not wish to use an Arduino board where the driver code is available and is instead interested in using the PIC32MX250F128B.
 
I've worked on custom board projects with him using this processor in the past but am busy on other projects at this time and am looking for short cuts from doing all the research and development from scratch.
 
So if you're still willing I'd appreciate whatever insights I can glean from your working code.
 
Lloyd
post edited by lloyddean - 2017/10/29 07:27:54
#17
lloyddean
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2011/07/08 21:42:55
  • Location: Seattle, WA
  • Status: offline
Re: inline statements in PIC32 2017/10/27 14:55:52 (permalink)
0
Sorry for not answering the question concerning the displays interface but I was waiting for answer to that query myself.
 
The answer appears to yes and he indicates a purchase of the display from a vender on ebay.
 
<https://www.ebay.com/itm/...7675.c100009.m1982>
 
EDIT:  This is for a personal project not commercial
post edited by lloyddean - 2017/10/27 18:30:09
#18
scinutz
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2018/10/05 19:16:52
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2018/10/08 12:46:31 (permalink)
0
I am curious as to the Code you got working to get the Pic32 working with the Matrix... I recently ordered the 64x32 RGB LED matrix board as you mentioned.    I have one of the Pic32 chips / boards...  Basically i'm about to Delve into a Jr's Project and need some ideas on code to get the board working ...
 
Please help!!! 
 
Eric
 
 
#19
TonyShell
Junior Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2016/05/22 20:51:01
  • Location: 0
  • Status: offline
Re: inline statements in PIC32 2018/10/22 16:16:46 (permalink)
0
Hey scinutz,
 
  Sorry, I just saw your post.  I have code working for the RGB LED.  I haven't played with it for a while, because my project moved on to an LCD, but let me dig up the code for you.  What is your email?  Mine is tshelleman@juno.com.  Give me a day or two to dig it up.  I actually have it working for two displays side by side to make a 128 x 32 display with multiple color depth.  Do you still need the code?  Please let me know.
 
Tony
#20
Jump to:
© 2020 APG vNext Commercial Version 4.5