• AVR Freaks

Helpful ReplyHot!Setting Neopixel Hardware pulse PIC18F47Q43

Author
thecucarachon
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2020/10/17 16:40:32
  • Location: 0
  • Status: offline
2020/10/20 09:41:45 (permalink)
0

Setting Neopixel Hardware pulse PIC18F47Q43

Hello, I have a problem with a PIC18F47Q43 where I am trying to generate the pulse for the ws2812 (Neopixel) LEDs by hardware.
I am following this microchip tutorial (https://www.youtube.com/watch?v=hHLMnJs87VE), but there are already things that do not match the mcc. I can't assign the timer2 to the pwm, and the tmr postcaler can't go to the SPI either. Does anyone know how I can accommodate this?

Thanks!
#1
NKurzman
A Guy on the Net
  • Total Posts : 19034
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/20 10:01:10 (permalink)
4 (1)
You are not required to use MCC for everything.  If MCC does not do what you need you will have to code it directly.  Just insure MCC is not using any of the resources / Peripherals.
#2
thecucarachon
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2020/10/17 16:40:32
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/20 10:20:30 (permalink)
0
I agree whit that. If that's why I wrote it in the MCC forum, it would be good to know how to get to a configuration with the mcc, it would be left for more developers
#3
schneckster
Starting Member
  • Total Posts : 46
  • Reward points : 0
  • Joined: 2008/10/28 01:57:23
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/30 10:12:54 (permalink) ☄ Helpfulby thecucarachon 2020/10/31 03:44:44
0
Hi,
 
I had the same problem with a PIC18F57Q43 on a Curiosity Nano.
 
I set it up like this...
System clock - HFINTOSC at 32MHz
TMR2 - clock source HFINTOSC, period 625ns no pre or post scale (as per example)
SPI2 - as per example, again, clocked from TMR2 post scaled (I needed to use SPI2 for my application)
PWM1_16Bit - I clocked from FOSC without pre-scaler, and then set the requested frequency as 1.6MHz, duty cycle 30% on output 1, 70% on output 2 (dunno if this is necessary, but I did it anyway) which gave a resolution of 4 bits.
CLC - As per the example.
 
I now have a 60 LED strip working quite well, with my wife looking forward to having a Cylon in the back garden... and she calls me a geek!?!
 
Cheers,
 
Schneckster
 
*edited - didn't say what I clocked TMR2 with, so I added that above.
post edited by schneckster - 2020/10/31 09:22:37
#4
thecucarachon
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2020/10/17 16:40:32
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/31 04:26:54 (permalink)
2 (1)
Hi, thank you very much for the reply! Sorry for my english!
I'm still laughing about "she calls me a geek" jajaja.
 
I'm testing what you told me, with the clock settings at least the SPI module now works, but I have the same problem that when I add the CLC it tells me that I have to configure the PWM module, look at the image that I attach, I made a new clean project. And since it didn't work for me, I also tried to use the PIC18F57Q43 and I get the same results, which version of MPLABX and MCC? Or could you give me a setup so I can test it?
" />
" />
 
" />" />" />" />
#5
Mysil
Super Member
  • Total Posts : 3952
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/31 06:28:24 (permalink) ☄ Helpfulby thecucarachon 2020/11/01 04:05:37
0
Hi,
Instead of 16-bit PWM1_16BIT,     You may try to use CCP2  in 10-bit PWM mode for the PWM signal.
 
    Mysil
#6
BroadwellConsultingInc
Super Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2020/06/09 06:07:55
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/31 06:51:23 (permalink)
0
Depending on your needs and what your PIC can do, the CLC and PWM may be an overly complex way to do this.  On a PIC24FJ256GA702 I was able to do a fairly simple implementation that only used the SPI SDO line fed by the DMA.  The PIC18F57Q43 also has DMA fed SPI.  If you can get the clocks to line up right, you may be able to use the same technique.
 
I did a couple of youtube videos on the design:
https://youtu.be/_HJepzYc6_0
https://youtu.be/rT4liNlJ7EI
 
The MPLAB project is available in the "Fun Stuff" section of my website.
 
#7
BroadwellConsultingInc
Super Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2020/06/09 06:07:55
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/31 06:53:56 (permalink)
1 (1)
Whoops, forgot to click "add signature" and the forum is giving me "access denied" when I try to edit the post.
 
Web site location is:
 
 https://www.broadwell.consulting/fun-projects
#8
schneckster
Starting Member
  • Total Posts : 46
  • Reward points : 0
  • Joined: 2008/10/28 01:57:23
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/10/31 08:29:07 (permalink)
0
Hi Cucarachon,
 
In your TMR2 settings, you have FOSC/4 as the clock source. I set mine to HFINTOSC. When I had it set to FOSC/4, the LED's didn't work. I think having them all set to the same clock gives it some synchronisation, which is why on the example, everything was set to TMR2's output. The timings on Neopixels are bit strict - overly so, in my opinion.
 
I'm using MPLABX 5.40 and MCC 4.0, though I don't think it'll make too much of a difference.
 
I get the same messages about setting up the PWM and CLC, etc. They're listed as hints or info, rather than warnings or errors, so I've sort of ignored them as I have LED's working under my control, now. Why it's telling me about the DMA when I've got it disabled, I don't know.
 
Also, I'm using a PIC18F57 while you're using a '47. There may be subtle differences between the devices, but hopefully, what I find to work may help.
 
Have you got any LED's working?
I have found that I got weird colours at first... then I noticed the Neopixels expect the data to be sent GRB instead of RGB. The colours made sense when I realised that... and yes, at her Ladyship's request, I now have a Cylon mode! It was a little unsettling when she started making the noise to go with it!?!
 
Cheers,
 
Schneckster
post edited by schneckster - 2020/10/31 09:17:23
#9
thecucarachon
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2020/10/17 16:40:32
  • Location: 0
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/11/01 04:29:23 (permalink) ☄ Helpfulby schneckster 2020/11/01 13:25:41
0
schneckster
In your TMR2 settings, you have FOSC/4 as the clock source. I set mine to HFINTOSC. When I had it set to FOSC/4, the LED's didn't work. I think having them all set to the same clock gives it some synchronisation, which is why on the example, everything was set to TMR2's output. The timings on Neopixels are bit strict - overly so, in my opinion.

 
Yes I had been confused in that configuration.
Finally, I take Mysil(user) config, I finally used the FOSC / 4 finally because I took the CPP to avoid the warning from the CLC that it gave me with the PWM.
 
schneckster
Also, I'm using a PIC18F57 while you're using a '47. There may be subtle differences between the devices, but hopefully, what I find to work may help.

 
Yes, I wanted to see if doing a project with that other microcontroller gave me the same precautions
 
I finally found the problem thank you all...
I began to test each module separately and the one that gave problems was the SPI.
There is a problem when the SPI module is included in MCC, when it is added it appears as master in the easy setup, but in the registers tab, if we are going to see the SPIxCON0 the MST bit is as slave, and in another part the module is disabled, I couldn't believe it, I thought it was me who had configured but I created another project and had the same problem.
 
 The final configurations are:
- TMR2 with FOSC / 4 625 ns.
- CPP1 as PWM 50%.
- SPI and CLC like the youtube video.

 
LEDs working
 

 
Thanks!
#10
Mysil
Super Member
  • Total Posts : 3952
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: Setting Neopixel Hardware pulse PIC18F47Q43 2020/11/01 07:49:41 (permalink)
0
Hi,
Some of the explaination is this:
When Timer2 (or 4 or 6) is used with one of the CCP peripherals for 10 bit PWM, 
then 2 bits of CCP resolution is taken from the instruction clock in the CPU,
or eventually the prescaler for the timer.
thus clock signal for the 8 bit timer is taken from FOSC/4.
Thus PWM duty cycle resolution can be set with up to 10 bits, even if PWM period can only be specified with 8 bits. 
 
Besides, in many older PIC devices, FOSC/4 was the only option available.
 
    Mysil
#11
Jump to:
© 2020 APG vNext Commercial Version 4.5