Hope someone can help with this
I am new to the R4 as well as the 7FA4M1AB3CFM#AA0 micro-controller`` and I am almost 100% sure that’s the real problem
This is what I am trying to do:
General PWM Timer CH7 is setup to achieve these goals
input frequency = 48Mhz
Outputs on GTIOC7A and GTIOC7B
GTIOC7A high when stopped
GTIOC7A goes low upon compare match
GTIOC7A goes high upon overflow
GTIOC7B Low when stopped
GTIOC7B goes High upon compare match
GTIOC7B goes low upon overflow
Runs at full 16 bits-1, so output frequency is 48Mhz/65534
GPT167_GTPR = 0xFFFE
Special case is when the compare match register is set to 0xFFFF one greater than the value in GPT167_GTPR the compare match will never occur and the output will remain at overflow value
But for some reason its not working pin 9 stays high, pin 8 stays low.
I suspect that something is not being setup properly but I cannot see it
This sketch uses Susan Parker’s “ra4m1_minima_register_defines.h”
A lot of thanks to Susan for all her hard work on this
Because I am a new user I cannot upload code so I am going to paste it below, I started with the Blink example and it grew from there
I hope I am using this forum correctly
#include "susan_ra4m1_minima_register_defines.h" // I found this on github
void GPT167setup()
/*
Setup PWM Ch7 GPT167 Figure 22.2 Association between GPT channels and module names
Clock = 48Mhz
Saw-Wave PWM Runs at full 16 bits-1 so output freq is 48Mhz/65534 *GPT167_GTPR = 0xFFFE;
Output A GTIOC7A on pin 28 (QFP64) Arduino pin8 Table 22.3 I/O pins of GPT
Output B GTIOC7B on pin 29 (QFP64) Arduino pin9
GTIOC7A high when stoped Arduino pin 8
GTIOC7A goes low upon compare match
GTIOC7A goes high upon overflow
GTIOC7B Low when stoped Arduino pin 9
GTIOC7B goes High upon compare match
GTIOC7B goes low upon overflow
*/
{
*GPT167_GTWP = 0x0000A500; // General PWM Timer Write-Protection Register (GTWP) 22.2.1
*PMISC_PWPR = 0x00; // Write-Protect Register (PWPR) 19.2.6
*PMISC_PWPR = 0x40; // Write-Protect Register (PWPR) 19.2.6
*PFS_P304PFS = (0b00011 << 24); // Select PSEL[4:0] for GTIOC7A - See Table 19.10 19.2.5
*PFS_P304PFS |= (0x1 << 16); // Port Mode Control - Used as an I/O port for peripheral function 19.2.5
*PFS_P303PFS = (0b00011 << 24); // Select PSEL[4:0] for GTIOC7B - See Table 19.10 19.2.5
*PFS_P303PFS |= (0x1 << 16); // Port Mode Control - Used as an I/O port for peripheral function 19.2.5
*MSTP_MSTPCRD &= 0xFFFFBFBF; // Module Stop Control Register D 10.2.5
*GPT167_GTSSR = 0x80000000; // b31 CSTRT Software Source Counter Start Enable 22.2.5
*GPT167_GTPSR = 0x80000000; // b31 CSTOP Software Source Counter Stop Enable
*GPT167_GTCSR = 0x80000000; // b31 CCLR Software Source Counter Clear Enable
*GPT167_GTCR = 0x00000000; // General PWM Timer Control Register (GTCR) 22.2.12
*GPT167_GTCLR = 0x00000008; // General PWM Timer Software Clear Register 22.2.4
*GPT167_GTUDDTYC = 0x1; // General PWM Timer Count Direction and Duty Setting Register 22.2.13
*GPT167_GTIOR = 0x01450049; // General PWM Timer I/O Control Register 22.2.14
*GPT167_GTBER = 0x00000002; // General PWM Timer Buffer Enable Register 22.2.17
*GPT167_GTCCRA = 0xFFFF; // General PWM Timer Compare/Capture Register A 22.2.19
*GPT167_GTCCRB = 0xFFFF; // General PWM Timer Compare/Capture Register B 22.2.19
*GPT167_GTPR = 0xFFFE; // General PWM Timer Cycle Setting Register 22.2.20
*GPT167_GTSTR |= 0x08; // Start Timer - General PWM Timer Software Start Register (GTSTR) 22.2.2
*GPT167_GTCCRB = 0x07FF; // Arduino pin D9 General PWM Timer Compare/Capture Register B 22.2.19
*GPT167_GTCCRA = 0x07FF; // Arduino pin D8 General PWM Timer Compare/Capture Register A 22.2.19
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(12,LOW);
pinMode(11, OUTPUT);
digitalWrite(11,LOW);
pinMode(10, OUTPUT);
digitalWrite(10,LOW);
// pinMode(8, OUTPUT);
// pinMode(9, OUTPUT);
// analogWrite(9, 10);
// analogWrite(8, 10);
GPT167setup();
}
// the loop function runs over and over again forever
void loop()
{
*PORT1_POSR = 0x0800; // turn the LED ON
delay(100); // wait for a 100ms
*PORT1_PORR = 0x0800; // turn the LED off
delay(1000); // wait for a second
}