View previous topic :: View next topic |
Author |
Message |
bmete
Joined: 13 Jul 2023 Posts: 37
|
Compilation problems on WS2812 code in Code Library |
Posted: Fri Jul 21, 2023 7:38 am |
|
|
Hello everyone,
Regarding this code:
http://www.ccsinfo.com/forum/viewtopic.php?t=54122
I tried this code on PIC18F4685 on the breadboard, tx pin = c6 rx pin = c7 and it worked without any issue. So chip is ok code is ok.
After that I try to this code with PIC18f4685 on my PCB and my chip's Tx/Rx pins are connected to the RS485 line so I think I can not use them for drive the LED Strip. On my PCB ws2812b data in pin is connected to the A0. When I try to config A0 pin as rs485 transmit and A1 rs485 receive program gives me an error which is "baud rate is out of range". And also its gave me 6 errors more which are on rs485.c
*** Error 102 "D:\******\Drivers\rs485.c" Line 118(21,34): Expect comma
*** Error 102 "D:\******\Drivers\rs485.c" Line 119(21,26): Expect comma
*** Error 102 "D:\******\Drivers\rs485.c" Line 193(24,34): Expect comma
*** Error 102 "D:\******\Drivers\rs485.c" Line 208(24,37): Expect comma
*** Error 102 "D:\******\Drivers\rs485.c" Line 239(13,14): Expect comma
*** Error 102 "D:\******\Drivers\rs485.c" Line 281(13,14): Expect comma
Any idea about this issue? Is there any limit to the pins which configured with software?
Any help will be appreciated.
edit:
When I changed the rs485pins as A0 and A1 no matter what above 6 errors occurring. For testing I left the main.c is default. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Jul 21, 2023 3:20 pm |
|
|
I don't use that PIC, but downloaded the datasheet. It can only go up to 40MHz and the test program requires a clock of 64MHz.
That's probably why the 'out of range' error occurs for the baud rate.
The 'missing comma' error sounds like when you edited the driver, you forgot a comma.
Generally speaking , you should make a copy of the CCS driver and edit the COPY, not the original file. That way you'll always have the original to use. It's too easy to make 2-3 changes with an error, then not know WHAT was the correct code....BTDT... |
|
|
bmete
Joined: 13 Jul 2023 Posts: 37
|
|
Posted: Sat Jul 22, 2023 6:53 am |
|
|
Hello temtronic,
I did not made any changes in the rs485.c file. Actually I am doing nothing more than just configure pins in the project wizard screen.
Error occurs only when I change the rs485 Tx/Rx pin configuration on the project wizard screen. Does not matter which pin I assign. If I leave all the rs485 pins on default configuration, then there is no error.
The other thing I am wondering is: Can I assign RS485 pins to any pin I want as software? and can i use these pins without any limit as if they are hardware Tx/Rx pins? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sat Jul 22, 2023 8:53 am |
|
|
I don't use the 'project wizard' so don't know if it really edit's the rs485 driver code to change the pin allocations.
I suspect it doesn't as it'd be a disaster !!!!
others will know. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Jul 23, 2023 2:16 am |
|
|
This driver, cannot use a software RS232. It needs the speed only the
hardware can manage. Also needs a UART that supports inverting the
output (only a few support this).
Now it sounds as if you are moving your RS485, so you can use the
hardware?. If so, great. However there are limitations on what pins can
be used for the software RS485. The software needs to be able to receive
an interrupt what serial data arrives. So either use the UART, or a pin
supporting an interrupt for the receive. It can't work without this, |
|
|
bmete
Joined: 13 Jul 2023 Posts: 37
|
|
Posted: Mon Jul 24, 2023 12:45 am |
|
|
Hello Ttelmah,
I want to tell you a little bit about my circuit. I am using 18f2520 in real project (on PCB). I'm testing the software on 18f4685 before modifying the PCB. (I only have 4685 for test.) I am sharing the hardware around the chip below.
[Img] https://ibb.co/mFrP7Wd [/Img]
As you can see here, the RC6 and RC7 pins (hardware supported pins) are connected to the SN75176 to communicate with the outside, so I cannot use this port to drive an LED.
I connected the A0 pin of the chip to the "data in" pin of the WS2812. My thought was to drive the leds from here. But as far as I can see, I can't do this with the A0 pin. So I changed my plan and I'm thinking of driving the LEDs with hardware pins (RC6/RC7) and communicating with the outside with other pins. (I thought I wouldn't need the speed needed to run the LED driver.)
For this purpose, when I try to configure the RS485 pins via project wizard with both chips, I get the errors I mentioned in my first message above on 4685.
If I do the config for 2520:
*** Error 100 "C:\****\main.h" Line 7(5.79): USE parameter value is out of range Not a number: NONE
I am getting this error and encounter the following NOTE.
#include <rs485.c>//NOTE: only one RS485 port is supported by the driver
Based on your advice, I looked at the Datasheet and tried to find the appropriate pin. I tried to configure interrupt pins such as RB0, RB1, RB4, RB5, but I still got the same error.
In short, what I have to do is both driving the LEDs and communicating with the outside via SN75176 (RS485). As I said before, I can make all kinds of modifications on the PCB, this board is a prototype and I have a chance to fix everything in the original design, but first I need to make the system work somehow. I don't know if I'm missing something or trying something impossible. I need help with this. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Jul 24, 2023 1:49 am |
|
|
Simple thing. You cannot do this is software. Problem is a software UART
just cannot do the timings needed for this device. Cannot get that fast.
It is possible to do it using the UART, or the SPI.
The basic operation is the same, except the output bytes used have to
be slightly tweaked to allow for there not being a stop bit.
So, the big question is whether you can connect this device to the pins
used by the SPI port?. If not, then you are going to have to rethink, and
possibly use a different PIC that has multiple UARTs (most newer ones do). |
|
|
bmete
Joined: 13 Jul 2023 Posts: 37
|
|
Posted: Mon Jul 24, 2023 2:00 am |
|
|
RC5 is a free pin on my design it is also SPI data out pin, I can connect RC5 to the WS2812 data in, and the communications pins RC6/RC7 will stay connected to the SN75176.
Will this work what do you think? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Jul 24, 2023 2:08 am |
|
|
Potentially yes. However, you then have to tweak the bytes sent. |
|
|
bmete
Joined: 13 Jul 2023 Posts: 37
|
|
Posted: Mon Jul 24, 2023 2:41 am |
|
|
I tried to configure RC5 pin as a RS232 Tx pin but compiler gives an error which is "baud rate out of range".
This is the main.h file:
Code: |
#include <18F2520.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#use delay(clock = 40M)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,FORCE_SW)
#use rs232(stream = LED_STREAM, baud = 10000000, xmit = PIN_C5, bits = 8, parity = N, stop = 0, ERRORS, INVERT)
|
I configured two RS232 ports;
First #use rs232 is for communication port,
second #use rs232 is for WS2812
When I decrease the baud rate to 500000, there is no error but now the LED's does not work.
Is there any mistake on my configuration?
Edit: Is there any way I can drive the WS2812 without using the rs232 port? I've searched this forum and the internet but haven't found a working example I can use. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Jul 24, 2023 5:27 am |
|
|
The WS2812 has a very specific time critical input.
A 'zero' bit is .35us on, .8 us off while a 'one' bit is .7 us on and .8 us off.
So it is simple to control, just turn the output pin of the PIC, on/off at the correct speed and duration to send the data to the WS2812.This is old school 'bit banging',usually done in Assembler to ensure proper timing of the bits.
Someone a long time ago figured out that using a hw UART on a fast clocked micro could 'simplify' the driver for the WS2812.
Years ago I did the 'old school' technique using a PIC18F46K22 just to see what's involved so I know it can be done. It does require you to calculate instruction times and 'pad' code(a few NOPs ) to get the proper timings. |
|
|
bmete
Joined: 13 Jul 2023 Posts: 37
|
|
Posted: Mon Jul 24, 2023 5:45 am |
|
|
Hello temtronic,
Thanks for the information, nice to hear that it can be done without using UART.
The calculations that you mentioned, can you please give me a hint about this? Or can you guide me on this? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Jul 24, 2023 5:59 am |
|
|
Listed to what you are being told.
A software UART cannot do this speed.
You have already got the hardware UART configured, so the second RS232
becomes a software UART. Result 'baud rate out of range'. Because it
cannot do this speed.
Now the driver you are trying to use gets the accurate timing needed by
using the hardware UART. You can get the same effect by using the hardware
SPI to do this. You then have to change the data sent, and the pattern
slightly. However key thing is you have to setup the SPI (not RS232) to
do this and send the data to the SPI (not the UART). You have to actually
reconfigure the driver to use this. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Jul 24, 2023 6:04 am |
|
|
If you look in the datasheet for your PIC, there's a section called 'Instruction set summary' which lists all the commands the PIC can do.
A 'BSF' instruction Sets a Bit on a File register ( sends a 'one' to an output pin for you...) ,and it takes one cycle to execute
From memory.... if you were using a PIC16F84 running at 4Mhz, a BSF would take 1us ( 4MHz /4 )
You'll have to look in the 'oscillator / clock' chapter to see what a 'cycle' is. It's different depending on the PIC.some are clock /4, some clock/2, others ???
So two key details...
1) determine the speed of a 'cycle' based on your clock ( I think 40Mhz )
2) cut code to create the WS2812 bits for 'one' and 'zero'
here's a 'cheat'....
google 'bitbanged WS2812', there's an Ardunio hit !!! it should provide some details that you can use. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Jul 24, 2023 6:12 am |
|
|
I think he was talking about 32MHz.
Key thing is to save the clock time imposed by standard_io on this. So
instead use either fast_io, or directly talk to the port register.
The timings are tight, but there are significant margins on what the chip
allows. (I think +/-150nsec if I remember right?).
However big problem is if you have anything else going on. You must
ensure that nothing else needs to be handled while the pulse train is being
send. Disable interrupts etc.. |
|
|
|