Arduino Uno R3 to read CAN-Bus and control PWM @ 150Khz problem...

Hello dear all,

I´m a newbie to this Arduino stuff, but i had an ideia and i would like to accomplish my goal.
This goal is to read Can-Bus and acording to the message toggle different PWM values through a pin connected to a N channel MOSFET driving a Led Auxiliary Light on my car…
My problem is that acording to some info i received, i will need a PWM signal of about 100-150Khz…
And for this the analogWrite function will not work…
Can you HELP ME with?
I will have available for PWM pins 5 and 6…
I´ve copied the code i have here:

#include <SPI.h>
#include "mcp_can.h"

INT32U canId = 0x000;
unsigned char len = 0;
unsigned char buf[8];
char str[20];

const int SPI_CS_PIN = 9;
MCP_CAN CAN(SPI_CS_PIN);

int auxLights = 5;   //  pin for PWM control module (i´ve read that pins 5 and 6 have a frequency of 980 Hz)
int diagOk = 8;   //  diagnostic led pin to check for “CAN INIT OK”
int levelZero = 0;     // lights off
int levelDay = 96;     // daylight intensity
int levelNight = 32;   // night intensity
int levelMax = 255;    // max intensity

void setup()
{
 pinMode(auxLights, OUTPUT);
 pinMode(diagOk, OUTPUT);

START_INIT:

 if (CAN_OK == CAN.begin(CAN_500KBPS))
 {
   digitalWrite(diagOk, HIGH);
 }
 else
 {
   digitalWrite(diagOk, LOW);
   goto START_INIT;
 }
}

void loop()
{
 if(CAN_MSGAVAIL == CAN.checkReceive()) 
 {
   CAN.readMsgBuf(&len, buf);
   canId = CAN.getCanId();

   switch (canId)
   {

   case 740:
     if (buf[4] == 64 && buf[6] == 149)
     {
       analogWrite(auxLights, levelZero);
     }
     else if (buf[4] == 64 && buf[6] == 165)
     {
       analogWrite(auxLights, levelMax);
     }
     else if (buf[4] == 128 && buf[6] == 149)
     {
       analogWrite(auxLights, levelNight);
     }
     else if (buf[4] == 128 && buf[6] == 165)
     {
       analogWrite(auxLights, levelMax);
     }
     else if (buf[4] == 64 && buf[6] == 150)
     {
       analogWrite(auxLights, levelDay);
     }
       else if (buf[4] == 64 && buf[6] == 166)
     {
       analogWrite(auxLights, levelMax);
     }
       else if (buf[4] == 128 && buf[6] == 85)
     {
       analogWrite(auxLights, levelDay);
     }
       else if (buf[4] == 128 && buf[6] == 101)
     {
       analogWrite(auxLights, levelMax);
     }
     else
     {
       analogWrite(auxLights, levelZero);
     }
     break;

Kind Regards,
Luis.


Please HELP!
Need a code to PWM a Led Light at 150Khz with my arduino Uno R3…
I´m using a Arduino UNO R3 with a CAN-BUS shield to control a PWM signal using an output pin on the Uno to drive a LED auxiliary light. When using the normal PWM mode only testing with a Led on the breadboard it works, but when using to control the Auxiliary light it doesn´t dim…
I discovered that it´s beacause it will need a 150Khz PWM signal…
I would like to use pins 5-6… my CANbus shield is using pins 13-12-11-10…

Thank you for your kind help…
Cheers!


Forget to mention on previous post that i will be using for PWM control to the light the Sparkfun MOSFET power control kit ( SparkFun MOSFET Power Control Kit - COM-12959 - SparkFun Electronics ).
Hope that it works!
And hope that Nick Gammon can help me with.
Cheers!


Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Do not cross-post. Do not hijack. Use
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags when posting code.